-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·96 lines (74 loc) · 2.07 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
#!/bin/sh
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
xdg_bin_home="${XDG_BIN_HOME:-$HOME/.local/bin}"
APPLICATION_NAME="GitMini"
bin_name="gitmini"
configure_install_aliases() {
commands="publish unpublish review start refresh current pause combine update list rename delete"
for cmd in $commands; do
git config --global "alias.$cmd" "!${bin_name} $cmd"
# git config --global "alias.$cmd" "!$0 $cmd"
done
}
# Function: install
#
# Install GitMini in $XDG_BIN_HOME and set up global aliases for the exposed commands.
configure_install() {
_out_name="$1"
if [ ! -e "$xdg_bin_home" ]; then
mkdir -p "$xdg_bin_home"
elif [ ! -d "$xdg_bin_home" ]; then
printf "${RED}error: %s is not a directory${NC}\n" "$xdg_bin_home" >&2
exit 1
fi
install -m 755 "$_out_name" "$xdg_bin_home/$bin_name"
configure_install_aliases
printf "${GREEN}%s installed successfully.${NC}\n" "$APPLICATION_NAME"
}
# Function: uninstall
#
# Uninstall GitMini from $XDG_BIN_HOME and unset global aliases for the exposed commands.
configure_uninstall() {
_out_name="$1"
installed_out="$xdg_bin_home/$bin_name"
if [ -e "$installed_out" ]; then
rm -rf "$installed_out"
fi
commands="publish unpublish start refresh current pause combine update list rename delete"
for cmd in $commands; do
git config --global --unset "alias.$cmd"
# git config --global --unset "alias.$cmd"
done
printf "${GREEN}%s uninstalled successfully.${NC}\n" "$APPLICATION_NAME"
}
if [ "$#" -lt 1 ]; then
action="install"
else
action="$1"
shift 1
fi
case "$action" in
install-aliases)
configure_install_aliases
exit 0
;;
esac
out_name="$(dirname "$0")/gitmini.sh"
if [ ! -e "$out_name" ]; then
printf "${RED}error: %s does not exists${NC}\n" "$out_name" >&2
exit 1
fi
case "$action" in
install)
configure_install "$out_name"
;;
uninstall)
configure_uninstall "$out_name"
;;
*)
printf "${RED}error: action %s not recognized${NC}\n" "$action" >&2
exit 1
;;
esac