-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall
More file actions
103 lines (87 loc) · 2.55 KB
/
Copy pathinstall
File metadata and controls
103 lines (87 loc) · 2.55 KB
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
#!/bin/sh
set -e
# Fancy color setup:
# https://unix.stackexchange.com/questions/9957/how-to-check-if-bash-can-print-colors
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
bold="$(tput bold)"
underline="$(tput smul)"
standout="$(tput smso)"
normal="$(tput sgr0)"
black="$(tput setaf 0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
white="$(tput setaf 7)"
fi
fi
insert_env_line() {
if [ -f "$1" ]; then
if [ -z "$(cat "$1" | grep "${ENV_LINE}")" ]; then
echo "${ENV_LINE}" >> "$1"
fi
fi
}
echo "Installing ${magenta}kiptup${normal}..."
BASE_DIR=${XDG_CONFIG_HOME:-$HOME}
KIPT_DIR=${KIPT_DIR-"$BASE_DIR/.kipt"}
KIPT_BIN_DIR="$KIPT_DIR/bin"
KIPT_MAN_DIR="$KIPT_DIR/share/man/man1"
BIN_URL="https://raw.githubusercontent.com/glihm/kipt/main/kiptup/kiptup"
BIN_PATH="$KIPT_BIN_DIR/kiptup"
ENV_PATH="$KIPT_DIR/env"
mkdir -p $KIPT_BIN_DIR
mkdir -p $KIPT_MAN_DIR
curl -# -L $BIN_URL -o $BIN_PATH
chmod +x $BIN_PATH
# Generates the env file on the fly
cat > $ENV_PATH <<EOF
#!/bin/sh
# Adds binary directory to PATH
case ":\${PATH}:" in
*:${KIPT_BIN_DIR}:*)
;;
*)
export PATH="${KIPT_BIN_DIR}:\$PATH"
;;
esac
EOF
chmod +x $ENV_PATH
# This detection here is just for showing the help message at the end.
IS_SUPPORTED_SHELL=""
if [ -n "$ZSH_NAME" ]; then
IS_SUPPORTED_SHELL="1"
fi
case $SHELL in
*/bash)
IS_SUPPORTED_SHELL="1"
;;
*/fish)
IS_SUPPORTED_SHELL="1"
;;
*/ash)
IS_SUPPORTED_SHELL="1"
;;
*/zsh)
IS_SUPPORTED_SHELL="1"
;;
esac
# Inserts this line into whatever shell profile we find, regardless of what the active shell is.
ENV_LINE=". \"${ENV_PATH}\""
insert_env_line "$HOME/.profile"
insert_env_line "$HOME/.bashrc"
insert_env_line "$HOME/.bash_profile"
insert_env_line "${ZDOTDIR-"$HOME"}/.zshenv"
insert_env_line "${ZDOTDIR-"$HOME"}/.zshrc"
insert_env_line "$HOME/.config/fish/config.fish"
echo
if [ -n "$IS_SUPPORTED_SHELL" ]; then
echo "Run '${yellow}. ${ENV_PATH}${normal}' or start a new terminal session to use kiptup."
echo "Then, simply run ${magenta}kiptup${normal} to install kipt."
else
echo "kiptup: could not detect shell. Add '${yellow}. ${ENV_PATH}${normal}' to your shell profile, or manually add '${yellow}${KIPT_BIN_DIR}${normal}' to your PATH environment variable."
fi