-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
install
executable file
·104 lines (91 loc) · 2.47 KB
/
install
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
#!/usr/bin/env bash
awesome_dir="$HOME/.local/share/awesome"
bin_dir="$HOME/.local/share/bin"
# version="0.1.1"
# if ((BASH_VERSINFO[0] < 4)); then
# printf '%s\n' "Error: This requires Bash v4.0 or higher. You have version $BASH_VERSION." 1>&2
# exit 2
# fi
fn_confirm() {
local item=$1
read -rp "Do you want to remove $item? yes/y or no/n " PANS
ans=$(echo "$PANS" | cut -c 1-1 | tr "[:lower:]" "[:upper:]")
echo $ans
}
# check if a dir exist. if not create it and add $HOME/awesome path to config file
fn_checkDir() {
if [[ -z $1 ]]; then
echo "Specify the directory." >&2
exit
fi
if [[ ! -d $1 ]]; then
mkdir -p "$1"
echo "$1 directory is created." >&2
fi
}
fn_check_cmd() {
if [ ! "$(command -v "$1")" ]; then
echo "Please install $1" >&2
exit
fi
}
# create a symlink in bin
fn_create_symlink() {
# find the name of repo
repo_name=$1
# add a symlink
ln -sf "${awesome_dir}/${repo_name}/${repo_name}" "${bin_dir}/${repo_name}"
}
fn_find_symlinks() {
paths=$(find "$bin_dir" -type l)
echo "$paths"
}
# Run git clone and create a symlink
fn_install() {
fn_checkDir "$awesome_dir"
fn_checkDir "$bin_dir"
fn_check_cmd git
cd "$awesome_dir" || exit
url="https://github.com/shinokada/awesome.git"
repo="awesome"
{ git clone "${url}" && fn_create_symlink "${repo}"; } || exit
echo "${repo} installation completed."
echo "Add the following to your your terminal config file, such as .zshrc or .bashrc."
echo 'export PATH=$HOME/.local/share/bin:$PATH'
echo "Try ${repo} -h or which ${repo}."
}
# Removes the awesome symlinks and dir
fn_uninstall() {
echo "Finding symlinks ..."
if [[ $(fn_confirm symlinks) = "Y" ]]; then
# mac doesn't have mapfile
# mapfile -t links < <(fn_find_symlinks)
links=($(fn_find_symlinks))
for link in "${links[@]}"; do
unlink "$link"
echo "Removed the ${link} symlink."
done
fi
if [[ $(fn_confirm awesome-directory) = "Y" ]]; then
echo "Uninstalling awesome directory ..."
rm -rf "$awesome_dir"
echo "Uninstalled awesome directory."
exit
fi
}
fn_main() {
if [ $# -eq 1 ]; then
case $1 in
"install")
fn_install
;;
"uninstall")
fn_uninstall
;;
esac
else
echo "Something wrong."
exit 1
fi
}
fn_main "$@"