-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·61 lines (51 loc) · 1.51 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
#!/usr/bin/env bash
set -euo pipefail
BIN_DIR="${HOME}/.local/bin"
BIN_FILE="${BIN_DIR}/zee"
RESET=$(tput sgr0)
# shellcheck disable=SC2034
readonly RESET
RED=$(tput setaf 1)
# shellcheck disable=SC2034
readonly RED
main() {
echo "Installing Zee to '${BIN_DIR}'."
mkdir -p "$BIN_DIR"
curl -sSL https://raw.githubusercontent.com/dnsv/zee/main/zee.sh -o "$BIN_FILE"
chmod +x "$BIN_FILE"
case "$SHELL" in
*/bash*)
# shellcheck disable=SC2016
add_to_file 'export PATH="$HOME/.local/bin:$PATH"' "${HOME}/.bashrc"
# shellcheck disable=SC2016
add_to_file 'eval "$(zee init bash)"' "${HOME}/.bashrc"
;;
*/zsh*)
# shellcheck disable=SC2016
add_to_file 'export PATH="$HOME/.local/bin:$PATH"' "${HOME}/.zshrc"
# shellcheck disable=SC2016
add_to_file 'eval "$(zee init zsh)"' "${HOME}/.zshrc"
;;
*/fish*)
add_to_file 'fish_add_path ~/.local/bin' "${HOME}/.config/fish/config.fish"
add_to_file 'zee init fish | source' "${HOME}/.config/fish/config.fish"
;;
*)
echo "Unknown shell $(basename "$SHELL"). Supported shells are bash, fish & zsh."
exit 1
;;
esac
echo "Installation complete. Zee will be available through the command \`z\`" \
"after sourcing your shell configuration file or restarting your terminal."
}
add_to_file() {
local text="$1"
local file="$2"
if ! grep -q "$text" "$file"; then
echo "Adding '${text}' to '${file}'."
echo "$text" >>"$file"
fi
}
{ # This ensures the script doesn't run until it's fully downloaded.
main
}