-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.zsh
executable file
·116 lines (104 loc) · 2.73 KB
/
install.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
#/usr/bin/env zsh
if [ -z $ZSH_VERSION ]; then
echo "Error: Need to be run in zsh!"
exit 1
fi
if [[ ! -f "$HOME/.oh-my-zsh/oh-my-zsh.sh" ]]; then
echo "Error: Install Oh my zsh first!"
exit 1
fi
if [[ -e "${HOME}/.zshrc_backup" ]]; then
echo "Error: ~/.zshrc_backup already exists!"
exit 1
fi
dir=$(readlink -f "$(dirname $0)")
profile_list=()
for filename in ${dir}/profiles/*; do
filename=$(basename $filename)
profile_list=($profile_list $filename)
done
echo "Choose profiles to active!"
echo
selected_profiles=()
finished="false"
while [[ "$finished" = "false" ]]; do
for ((i = 1; i <= $#profile_list; i++)); do
# $selected_profiles.contains($profile_list[i])
if (($selected_profiles[(I)$profile_list[i]])); then
toggle="[X]"
else
toggle="[ ]"
fi
echo "$toggle $i: $profile_list[i]"
done
echo ""
echo "[ ] f: Finish selection"
echo -n "Choose profile: "
read
if [[ $REPLY = "" ]]; then
echo "Select a valid profile!"
echo ""
elif [[ $REPLY = "f" ]]; then
echo ""
finished="true"
else
profile_selected=$profile_list[$REPLY]
if [[ -z $profile_selected ]]; then
echo "Select a valid profile!"
echo ""
fi
# $selected_profiles.contains($profile_selected)
if (($selected_profiles[(I)$profile_selected])); then
# $selected_profiles.remove($profile_selected)
selected_profiles[$selected_profiles[(i)$profile_selected]]=()
else
selected_profiles=($selected_profiles $profile_selected)
fi
echo ""
fi
done
if [[ ${#selected_profiles} -eq 0 ]]; then
echo "Error: No profile chosen"
exit 1
fi
echo "Selected profiles: $selected_profiles"
echo ""
if [[ -e "${HOME}/.zshrc" ]]; then
echo "Info: ~/.zshrc already exists - Moving it to ~/.zshrc_backup"
mv ${HOME}/.zshrc ${HOME}/.zshrc_backup
fi
cat > "${HOME}/.zshrc" <<- EOF
export MY_ZSH_PROFILES=(${selected_profiles})
. "${dir}/.zshrc"
EOF
function _copy_from_template_folder() {
template_folder="${dir}/profiles/${1}/templates"
if [[ -f "${template_folder}/$2" ]]; then
if [[ -e "${HOME}/$2" ]]; then
cat "${template_folder}/$2" >> "${HOME}/$2"
echo "Added template $2 from $1 to ~."
else
cp "${template_folder}/$2" ${HOME}
echo "Copied template $2 from $1 to ~."
fi
fi
}
for profile ("$selected_profiles[@]"); do
_copy_from_template_folder $profile '.localzsh_aliases'
_copy_from_template_folder $profile '.localzsh_env'
_copy_from_template_folder $profile '.localzsh_prompt'
postinstall_msg="${dir}/profiles/${profile}/postinstall.txt"
if [[ -e $postinstall_msg ]]; then
cat $postinstall_msg
echo ""
fi
postinstall="${dir}/profiles/${profile}/postinstall.zsh"
if [[ -e $postinstall ]]; then
echo "$profile:"
echo "Executing postinstall"
. $postinstall
echo ""
fi
done
echo ""
echo "Finished installation. Have fun!"