-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·78 lines (70 loc) · 1.91 KB
/
configure
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
#!/bin/zsh
set -e
autoload -Uz colors && colors
echo_center () {
# prints text to the center of the console
local cols=$(tput cols)
local pad=$((($cols - ${#1}) / 2))
repeat $pad printf ${2:-" "}
printf "$fg_bold[$3]%s$reset_color" $1
repeat $pad printf ${2:-" "}
printf "\n"
}
echo_color () {
# prints color name in color
echo -n "$fg_bold[$1]$1$reset_color"
}
# print banner
echo_center " zsh-cfg " "=" magenta
zsh_cfg_prompt_color () {
# ask user for the prompt color
local ZSH_COLORS=(black red green yellow blue magenta cyan white)
echo -n "Colors:"
for c in $ZSH_COLORS; echo -n " $(echo_color $c)"
echo
echo -n "Choose a prompt color: [$(echo_color cyan)] "
read ZSH_CFG_COLOR
ZSH_CFG_COLOR=${ZSH_CFG_COLOR:-cyan} # set default value
# check that selected color is valid
if [[ -n ${ZSH_COLORS[(r)$ZSH_CFG_COLOR]} ]]; then
echo "You chose $(echo_color $ZSH_CFG_COLOR)."
else
echo "Invalid color."
zsh_cfg_prompt_color
fi
}
zsh_cfg_prompt_color
zsh_cfg_prompt_extras () {
# ask user whether to install extras
echo -n "Install extras? [Y/n] "
read ZSH_CFG_EXTRAS
ZSH_CFG_EXTRAS=${ZSH_CFG_EXTRAS:-y}
if [[ $ZSH_CFG_EXTRAS =~ ^[Yy]$ ]]; then
echo "Installing transfer.sh alias..."
curl -# "https://gist.githubusercontent.com/nl5887/a511f172d3fb3cd0e42d/raw/d2f8a07aca44aa612b6844d8d5e53a05f5da3420/transfer.sh" >> ~/.zshalias.local
echo "Done."
elif [[ $ZSH_CFG_EXTRAS =~ ^[Nn]$ ]]; then
echo "Skipping extras."
else
echo "Invalid repsonse."
zsh_cfg_prompt_write
fi
}
zsh_cfg_prompt_extras
# write configuration
zsh_cfg_prompt_write () {
echo -n "Write configuration file? [Y/n] "
read ZSH_CFG_WRITE
ZSH_CFG_WRITE=${ZSH_CFG_WRITE:-y}
if [[ $ZSH_CFG_WRITE =~ ^[Yy]$ ]]; then
echo "ZSH_CFG_COLOR=$ZSH_CFG_COLOR" >> ~/.zshcfg
echo "Done."
elif [[ $ZSH_CFG_WRITE =~ ^[Nn]$ ]]; then
echo "Aborting."
return 1
else
echo "Invalid repsonse."
zsh_cfg_prompt_write
fi
}
zsh_cfg_prompt_write