-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·50 lines (42 loc) · 1.62 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
#!/usr/bin/env bash
# the ${IFS} is a constant used by bash to explode output into arrays.
# this assignment changes the default-behaviour to only split strings
# into arrays on linebreaks instead of (almost) all whitespace chars.
IFS=$'\n'
# abort if this script is not called within the repository.
if ! [ $(find $(pwd) -name "thibsy.sh") ]; then
printf "you must call this script within it's directory.\n"
exit 1
fi
# abort if zsh hasn't been installed yet.
if ! [ $(which zsh) ]; then
printf "Error: we use zsh (https://ohmyz.sh) as our internal shell, please install and set it up first.\n"
exit 1
fi
# create a zsh-profile if it doesn't already exist.
if ! [ -f "${HOME}/.zshrc" ]; then
# oh-my-zsh normally creates a template, if it exists we can use it.
if [ -f "${HOME}/.zshrc.example" ]; then
cp "${HOME}/.zshrc.example" "${HOME}/.zshrc"
else
touch "${HOME}/.zshrc"
fi
fi
zshrc_entries=(
# necessary for autocompletion
"source $(pwd)/completion.sh"
# might need some more in the future ...
)
# add all lines to the .zshrc profile if it doesn't already exist.
for entry in ${zshrc_entries[@]}; do
grep -qxF "${entry}" "${HOME}/.zshrc" || echo "${entry}" >> "${HOME}/.zshrc"
done
# install thibsy if it wasn't already installed beforehand.
if ! [ $(which thibsy) ]; then
# create a symlink to the ./thibsy.sh script that is located within the
# users local bin and mark the script as an executable.
ln -s "$(pwd)/thibsy.sh" /usr/local/bin/thibsy
chmod +x "$(pwd)/thibsy.sh"
fi
printf "Success: command was installed, try 'thibsy help' for possibilities.\n"
exit 0