-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·171 lines (144 loc) · 3.97 KB
/
install.sh
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
#!/usr/bin/env bash
options=(kitty neovim rofi spotify_player zsh starship)
CONFIG_DIR="$HOME/.config"
CURRENT_DIR="$(dirname "$(readlink -f "$0")")"
color_red="\033[1;31m"
color_white="\033[0m"
color_green="\033[1;32m"
color_blue="\033[1;34m"
print_option() {
printf " %s %s\n" "$1" "$2"
}
show_help() {
printf "${color_green}%s ${color_white}%s %s %s\n\n" "Usage:" "$0" "[OPTIONS...]"
printf "${color_green}%s\n${color_white}" "Options:"
print_option "-p, --no-zsh-plugins " "Don't install zsh plugins"
print_option "-S, --symlink " "Create symlinks instead of copying files"
print_option "-d, --delete, --no-backup" "Don't create backup files"
print_option "-i, --ignore <OPTIONS> " "Don't install specified files (-i zsh,rofi)"
print_option " " "OPTIONS: kitty, neovim, rofi, spotify_player, zsh, starship"
print_option "-s, --silent " "Don't show progress messages"
print_option "-h, --help " "Show this help message"
}
send_error() {
printf "${color_red}%s ${color_white}%s\n" "error:" "$1"
exit 1
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
valid_option() {
for option in "${options[@]}";
do
if [ "$1" == "$option" ]; then
return 0
fi
done
send_error "Invalid option: $1"
}
backup() {
if [[ -d "$1" || -f "$1" ]]; then
[[ "$delete" != "true" ]] && cp -r "$1" "${1}.backup"
rm -rf "$1"
fi
}
copy_files() {
if [[ "$symlink" == "true" ]]; then
ln -s "${CURRENT_DIR}/$1" "$2"
else
cp -r "$1" "$2"
fi
}
print_progress() {
[[ "$silent" != "true" ]] && printf "${color_blue}%s${color_white}$2" "$1"
}
start_progress() {
print_progress "Installing $1..." "$2"
}
finish_progress() {
echo -ne "\r\033[K"
print_progress "Installed $1" "\n"
}
clone_plugin() {
if [[ ! -d "$ZSH_PLUGINS_DIR/$2" ]]; then
print_progress "Cloning $2 plugin..." "\n"
git clone "https://github.com/${1}/${2}.git" "$ZSH_PLUGINS_DIR/$2"
else
print_progress "Already installed '$2' plugin" "\n"
fi
}
setup() {
start_progress "$1"
backup "${CONFIG_DIR}/$1"
[[ "$silent" != "true" ]] && sleep 0.7
copy_files "$1" "$CONFIG_DIR"
finish_progress "$1"
}
while [[ $# -gt 0 ]]; do
case "$1" in
-p | --no-zsh-plugins)
plugins="false"
shift
;;
-S | --symlink)
symlink="true"
shift
;;
-d | --delete | --no-backup)
delete="true"
shift
;;
-i | --ignore)
[[ -z $2 ]] && send_error "a value is required for 'ignore'" || ignore="$2"
shift 2
;;
-s | --silent)
silent="true"
shift
;;
-h | --help | help)
show_help
exit 0
;;
-* | --*)
send_error "unknown option: \`$1\`"
;;
*)
send_error "no such command: \`$1\`"
esac
done
if [[ ! -z $ignore ]]; then
IFS=','
for i in $ignore;
do
valid_option "$i" && eval "${i}"="false"
done
fi
[[ "$kitty" != "false" ]] && setup kitty
[[ "$rofi" != "false" ]] && setup rofi
[[ "$spotify_player" != "false" ]] && setup spotify-player
[[ "$neovim" != "false" ]] && setup nvim
if [[ "$zsh" != "false" ]]; then
start_progress zsh "\n"
backup "$HOME/.zshrc"
copy_files .zshrc "${HOME}"
if [[ "$plugins" != "false" ]]; then
ZSH_PLUGINS_DIR="${ZSH_CUSTOM:-${ZSH:-$HOME/.oh-my-zsh}/custom}/plugins"
[[ ! -d $ZSH_PLUGINS_DIR ]] && mkdir -p $ZSH_PLUGINS_DIR
clone_plugin grigorii-zander zsh-npm-scripts-autocomplete
clone_plugin redxtech zsh-kitty
clone_plugin MenkeTechnologies zsh-cargo-completion
clone_plugin zshzoo cd-ls
clone_plugin hlissner zsh-autopair
clone_plugin zsh-users zsh-autosuggestions
clone_plugin zsh-users zsh-syntax-highlighting
clone_plugin zsh-users zsh-completions
fi
print_progress "Installed zsh" "\n"
fi
if [[ "$starship" != "false" ]]; then
start_progress starship
backup "$HOME/.config/starship.toml"
copy_files starship.toml "${HOME}/.config"
finish_progress starship
fi