-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall
214 lines (199 loc) · 6.61 KB
/
install
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/zsh
local input
if [[ "$1" != '-f' && "$1" != '--force' ]]; then
clear
# Version check
local min_zsh_version='5.0.0'
if ! autoload -Uz is-at-least || ! is-at-least "$min_zsh_version"; then
>&2 echo "statusline: old shell detected, minimum supported: $min_zsh_version"
read -q input \?'Continue anyways? [n] '
echo
if [[ "$input" != 'y' ]] exit
echo
fi
# OS check
if [[ "$OSTYPE" != darwin* ]] print -P '%F{1}%UWarning%u%f: Mac-specific components (font location, terminal theme) will not be installed!'
# Info
cat <<EOH
This script will install the statusline prezto theme.
It will also install/setup prezto and other requisites as needed.
You can rerun this script anytime to change the theme's settings (without reinstalling).
EOH
if [[ -d ~/.oh-my-zsh/ ]] print -P '%F{1}%UWarning%u%f: oh-my-zsh will be uninstalled'
echo
read -q input\?'Continue? [y] '
echo
if [[ "$input" == 'n' ]] exit
echo
fi
#
# Uninstall oh-my-zsh
#
if [[ -d ~/.oh-my-zsh/ ]]; then
print -P '%B>>> Uninstalling oh-my-zsh%b'
local +h ZSH=~/.oh-my-zsh/
echo "source $ZSH/lib/functions.zsh"
source "$ZSH/lib/functions.zsh"
if (( $+functions[uninstall_oh_my_zsh] )); then
uninstall_oh_my_zsh
# Detect if oh-my-zsh uninstall switched to bash
if [[ "${$(sh -c 'echo $SHELL'):t}" != 'zsh' ]]; then
print -P '%B>>> Switching back to zsh%b'
echo 'chsh -s /bin/zsh'
chsh -s /bin/zsh
# If oh-my-zsh switches to bash, it leaves a dirty .zshrc
if [[ -s ~/.zshrc ]]; then
print -P '%B%F{1}>>> Renaming .zshrc to .zshrc.omz-backup%f%b'
print '(oh-my-zsh uninstall left a dirty .zshrc)'
mv ~/.zshrc ~/.zshrc.omz-backup
fi
fi
else
>&2 print -P '%F{1}%BError%b%f: Could not locate uninstall function'
print 'Please uninstall oh-my-zsh manually'
exit 1
fi
unset ZSH
fi
# Install prezto
if [[ ! -d "${ZDOTDIR:-$HOME}/.zprezto/" ]]; then
print -P '%B>>> Installing prezto%b'
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
print -P '%B>>> Linking zsh dotfiles%b'
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
dotfile="${ZDOTDIR:-$HOME}/.${rcfile:t}"
if [[ -s "$dotfile" ]]; then
echo "Importing $dotfile to $rcfile"
print -P "\n#\n# Import from $dotfile\n#\n\n" >>! "$rcfile"
cat "$dotfile" >> "$rcfile"
echo "Backing up $dotfile to $dotfile.backup"
mv "$dotfile" "$dotfile.backup"
fi
ln -s "$rcfile" "$dotfile"
done
unset dotfile
fi
#
# Install statusline
#
pushd "${ZDOTDIR:-$HOME}/.zprezto"
if [[ -d modules/prompt/external/statusline ]]; then
print -P '%F{1}%UWarning%u%f: "modules/prompt/external/statusline" directory already exists.'
print -P '%B>>> %F{1}Skipping statusline download%f%b'
else
print -P '%B>>> Downloading statusline%b'
git submodule add --depth 1 -- https://github.com/el1t/statusline.git modules/prompt/external/statusline
fi
# Install patched font
pushd modules/prompt/external/statusline
if [[ "$OSTYPE" == darwin* ]]; then
if [[ ! -s ~/Libary/Fonts/MenloforPowerline-Regular.otf ]]; then
read -q input\?'Install custom Powerline-patched font? [y]'
echo
if [[ "$input" == 'n' ]]; then
print -P '%F{1}%UWarning%u%f: font will default to block style'
else
print -P '%B>>> Installing Powerline-patched font (current user only)%b'
cp setup/MenloforPowerline-Regular.otf ~/Library/Fonts
fi
else
print -P '%B>>> Font already installed, skipping%b'
fi
fi
# Allow prezto to detect statusline
print -P '%B>>> Linking into prezto themes directory%b'
ln -fs "$PWD/prezto/prompt_statusline_setup" ../../functions/
# Replace current prezto theme in settings
pushd ../../../../runcoms
print -P '%B>>> Adding theme to zpreztorc%b'
if [[ "$OSTYPE" == darwin* ]]; then
# Change line
sed -i '' "/zstyle ':prezto:module:prompt' theme/c\\
zstyle ':prezto:module:prompt' theme 'statusline'
" zpreztorc
else
sed -i "/zstyle ':prezto:module:prompt' theme/c\\zstyle ':prezto:module:prompt' theme 'statusline'" zpreztorc
fi
# Add git plugin if necessary
if ! grep -q "'git' \\\\" zpreztorc ; then
print -P '%B>>> Adding git plugin to zpreztorc%b'
if [[ "$OSTYPE" == darwin* ]]; then
sed -i '' "/'completion' \\\\/a\\
\\ 'git' \\\\
" zpreztorc
else
sed -i "/'completion' \\\\/a\\\\ 'git' \\\\" zpreztorc
fi
fi
# If custom font was not installed, use block font
# $input will either be 'y' from 'Continue?' or the answer to 'Install font?'
# This should handle an answer of 'n' to the latter question
if [[ "$input" == 'n' ]]; then
if [[ "$OSTYPE" == darwin* ]]; then
sed -i '' "s/'statusline'/'statusline' -f block/" zpreztorc
else
sed -i "s/'statusline'/'statusline' -f block/" zpreztorc
fi
fi
# Prompt user to set statusline options
read -q input\?'Use double-line prompt? [y]'
echo
if [[ "$input" == 'n' ]]; then
if [[ "$OSTYPE" == darwin* ]]; then
sed -i '' "s/'statusline'/'statusline' -s/" zpreztorc
else
sed -i "s/'statusline'/'statusline' -s/" zpreztorc
fi
fi
read -q input\?'Use dark theme? [y] '
echo
if [[ "$input" == 'n' ]]; then
input='Light'
else
input='Dark'
if [[ "$OSTYPE" == darwin* ]]; then
sed -i '' "s/'statusline'/'statusline' -d/" zpreztorc
else
sed -i "s/'statusline'/'statusline' -d/" zpreztorc
fi
fi
# Enter modules/prompt/external/statusline directory
popd
if [[ "$OSTYPE" == darwin* ]]; then
input="Solarized $input"
# Set theme as default in Terminal.app
# from https://github.com/mathiasbynens/dotfiles/blob/master/.osx
osascript <<EOD
tell application "Terminal"
local allOpenedWindows
local initialOpenedWindows
local windowID
(* Store the IDs of all the open terminal windows. *)
set initialOpenedWindows to id of every window
(* Open the custom theme so that it gets added to the list
of available terminal themes (note: this will open two
additional terminal windows). *)
do shell script "open 'setup/$input.terminal'"
(* Wait a little bit to ensure that the custom theme is added. *)
delay 1
(* Set the custom theme as the default terminal theme. *)
set default settings to settings set "$input"
(* Get the IDs of all the currently opened terminal windows. *)
set allOpenedWindows to id of every window
repeat with windowID in allOpenedWindows
if initialOpenedWindows does not contain windowID then
(* Close the additional windows that were opened *)
close (every window whose id is windowID)
else
(* Change the theme for the initial opened terminal windows *)
set current settings of tabs of (every window whose id is windowID) to settings set "$input"
end if
end repeat
end tell
EOD
fi
# Return to original directory
popd; popd
unset input
print -P '%B>>> Statusline has been successfully installed. Please restart zsh to activate statusline.%b'