-
Notifications
You must be signed in to change notification settings - Fork 0
/
link-dotfiles.sh
executable file
·67 lines (57 loc) · 1.32 KB
/
link-dotfiles.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
#! /bin/bash
#
# Links dotfiles into the home directory
RED='\033[0;31m'
CYAN='\033[0;36m'
NC='\033[0m'
DIRECTORIES=(vim zsh x11 git pry)
usage() {
echo "Usage: [-ah]"
echo
echo " -a: attempts to link all scripts without prompts"
echo " -h: shows this message" 1>&2; exit 1;
}
while getopts ":ah" opt; do
case $opt in
a)
a=1
;;
h)
usage
;;
esac
done
touch $HOME/.env
for DIRECTORY in "${DIRECTORIES[@]}"; do
for FILEPATH in $DIRECTORY/*; do
FILENAME=`basename $FILEPATH`
DOTFILE=$HOME/.$FILENAME
if [ -z "${a}" ]; then
printf "${CYAN}Link .$FILENAME?${NC} "
read -n 1 -r RESPONSE
echo
until [[ $RESPONSE =~ ^[[yY]|[nN]$ ]]; do
printf "${RED}Please enter y/n${NC}"
echo; echo
printf "Link .$FILENAME? (y/n) "
read -n 1 -r RESPONSE
echo
done
fi
if [[ $RESPONSE =~ ^([yY][eE][sS]|[yY])$ ]]; then
# If the file exists and is a regular file
if [ -e $DOTFILE ] && [ ! -L $DOTFILE ]
then
echo "Moving ~/.$FILENAME to ~/.$FILENAME.old"
mv $DOTFILE $DOTFILE.old
fi
# If the file does not exist now, or never did
if [ ! -e $DOTFILE ]
then
echo "Linking .$FILENAME..."
ln -s `pwd`/$FILEPATH $DOTFILE
fi
fi
done
done
exit 0