-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdarwin.zsh
129 lines (116 loc) · 3.94 KB
/
darwin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
export PATH="/Applications/Docker.app/Contents/Resources/bin:$PATH"
unalias brew 2>/dev/null
brewser=$(stat -f "%Su" $(which brew))
alias brew='sudo -Hu '$brewser' brew'
batt () {
[[ $1 = "clear" ]] && echo -n > ~/.batt
if (pmset -g batt | grep Internal | grep estimate > /dev/null); then
batt=$(pmset -g batt | grep Internal |awk -F' ' '{print $3,$4}' | tr -d \;)
else
batt=$(pmset -g batt | grep Internal |awk -F' ' '{print $3,$4,$5,$6}' | tr -d \;)
fi
last=`tail -n 1 ~/.batt | awk -F " " '{ print $3}'`
this=`echo $batt | awk -F " " '{ print $2}'`
date=`date "+%H:%M"`
cat ~/.batt
echo $date $batt
[[ $last = 'charged' ]] && [[ $this = 'charged' ]] && return
[[ $1 = "cron" ]] && echo $date $batt >> ~/.batt
}
dfh () {
[[ $1 = "clear" ]] && echo -n > ~/.dfh
dfh=`df -h | head -2 | tail -1 | awk -F " " '{print $4}'`
date=`date "+%H:%M"`
last=`tail -n 1 ~/.dfh | awk -F " " '{ print $2}'`
[[ -f ~/.dfh ]] && cat ~/.dfh
echo $date $dfh
[[ $last = $dfh ]] && return
[[ $1 = "cron" ]] && echo $date $dfh >> ~/.dfh
}
nfy () {
netlify sites:list | grep url
}
themes() {
grep Name ~/Library/Application\ Support/iTerm2/DynamicProfiles/iterm.json | awk -F' ' '{print $3}' | awk -F'"' '{print $2}'
}
wallpaper () {
if [[ $# -eq 0 ]] ; then
echo "Available wallpapers:"
ls $HOME/wallpapers | grep .png | awk -F "." '{ print $1 }'
return
fi
if [[ -f $HOME/wallpapers/$1.png ]] ; then
osascript -e 'set desktopImage to POSIX file "'$HOME/wallpapers/$1.png'"
tell application "Finder"
set desktop picture to desktopImage
end tell'
return
fi
echo "Wallpaper not found"
echo "Available wallpapers:"
ls $HOME/wallpapers | grep .png | awk -F "." '{ print $1 }'
}
AdminQuestion () {
echo -ne "
Will $1 be an admin user?
$(ColorGreen '1)') Yes
$(ColorGreen '2)') No
$(ColorCyan 'Choose an option:') "
read a
array=(1 Yes yes Y y)
[[ ${array[*]} =~ $a ]] && admin=yes || admin=no
}
newuseroutput () {
echo -ne "
$(ColorGreen '1)') Lock screen and sign in as $1, accepting all defaults
$(ColorGreen '2)') Lock screen and sign back in here as `whoami` and run \"prepare\" from terminal
$(ColorGreen '3)') Lock screen and sign back in as $1, cd to ~/macfair and type \"make help\" for next steps
"
}
newuser () {
if [[ $# -eq 1 ]]
then
username=$1
displayName=$1
echo -ne "Specify password to be used for $1
$(ColorGreen Password): "
read password
AdminQuestion $1
highestUID=$( dscl . -list /Users UniqueID | /usr/bin/awk '$2>m {m=$2} END { print m }' )
nextUID=$(( highestUID+1 ))
sudo /usr/bin/dscl . create "/Users/$username"
sudo /usr/bin/dscl . create "/Users/$username" UserShell /bin/zsh
sudo /usr/bin/dscl . create "/Users/$username" RealName "$displayName"
sudo /usr/bin/dscl . create "/Users/$username" UniqueID "$nextUID"
sudo /usr/bin/dscl . create "/Users/$username" PrimaryGroupID 20
sudo /usr/bin/dscl . passwd "/Users/$username" "$password"
if [[ "$admin" = "yes" ]]
then
sudo /usr/bin/dscl . append /Groups/admin GroupMembership "$username"
fi
newuseroutput $1
else
echo Please specify user to be created
fi
}
prepare () {
if [[ $# -eq 1 ]]
then
sudo cp -r ~/.ssh /Users/$1/.ssh
sudo chown -R $1 /Users/$1/.ssh
sudo cp ~/.gitconfig /Users/$1/.gitconfig
sudo git -c core.sshCommand="ssh -i ~/.ssh/id_rsa" clone [email protected]:cerico/macfair /Users/$1/macfair
sudo chown -R $1 /Users/$1/macfair
else
echo Please specify user to be prepared
fi
}
# Avoid creating .DS_Store files on network or USB volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# Don’t automatically rearrange Spaces based on most recent use
defaults write com.apple.dock mru-spaces -bool false
# Automatically hide and show the Dock
defaults write com.apple.dock autohide -bool true
# Enable “Do Not Track”
defaults write com.apple.Safari SendDoNotTrackHTTPHeader -bool true