-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·81 lines (73 loc) · 2.36 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
#!/bin/bash
# Use !/usr/bin/env bash
LOCATION=$(pwd)
STOW_PACKAGE_LIST="bash vim tmux starship git"
STOW="no"
UNSTOW="no"
# HELP Message.
usage() {
cat 1>&2 <<EOF
Usage: $0 [-s] [-u] [-h]
-s Stow the dotfiles
-u Unstow the dotfiles
-h Print HELP message
EOF
exit 1
}
# Without any parameter print HELP message.
if [ $# -eq 0 ];
then
usage;
fi
# Parsing script parameters.
while getopts 'suh' opt; do
case "${opt}" in
s) STOW=yes ;;
u) UNSTOW=yes ;;
h) usage ;;
*) echo "Unknown option $opt" 1>&2; usage ;;
esac
done
shift "$(( OPTIND - 1 ))"
# Check if stow is installed
if [ ! -x "$(command -v stow)" ]; then
echo "Missing 'stow' binary. Read README.md for instructions."
exit 1
fi
# Setup EMAIL and NAME for gitconfig templates
git_config_templating() {
mkdir "${LOCATION}/git"
read -r -n 1 -p "Do you have personal and work git accounts? (Y/n) " more_accounts
case $more_accounts in
Y|y)
cp "${LOCATION}/gitconfig-multi" "${LOCATION}/git/.gitconfig"
echo -e "\nPlease provide your name and email address to be used for personal account"
read -r -p "Name: " name
read -r -p "Email: " email
sed -e "s/{{NAME}}/$name/g" -e "s/{{EMAIL}}/$email/g" "${LOCATION}/gitconfig-personal.tmpl" > "${LOCATION}/git/.gitconfig-personal"
echo "Please provide your name and email address to be used for work account"
read -r -p "Name: " name
read -r -p "Email: " email
sed -e "s/{{NAME}}/$name/g" -e "s/{{EMAIL}}/$email/g" "${LOCATION}/gitconfig-work.tmpl" > "${LOCATION}/git/.gitconfig-work"
;;
*)
echo "Please provide your name and email address to be used in .gitconfig file"
read -r -p "Name: " name
read -r -p "Email: " email
sed -e "s/{{NAME}}/$name/g" -e "s/{{EMAIL}}/$email/g" gitconfig.tmpl > "${LOCATION}/git/gitconfig"
;;
esac
}
# Stow the dotfiles to user HOME directory
if [ "$STOW" == "yes" ];
then
echo "Installing the dotfiles to HOME directory."
git_config_templating
stow -St ~ "${STOW_PACKAGE_LIST}"
# Unstow the dotfiles from user HOME directory
elif [ "$UNSTOW" == "yes" ];
then
echo "Uninstalling the dotfiles from the HOME directory."
stow -Dt ~ "${STOW_PACKAGE_LIST}"
rm -rf "${LOCATION}/git"
fi