-
Notifications
You must be signed in to change notification settings - Fork 2
/
dotfiles.sh
executable file
·70 lines (58 loc) · 1.4 KB
/
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
68
69
70
#!/usr/bin/env bash
DOTFILES_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
FILES=(.zshrc .zsh_profile .config/nvim .tmux.conf)
function healthcheck {
for FILE in ${FILES[@]}; do
printf "Checking $FILE..."
TARGET=$(readlink -f $HOME/$FILE)
if [ $TARGET == "$DOTFILES_DIR/$FILE" ]; then
echo -e "\033[0;32mPASS\033[0m"
else
echo -e "\033[0;31mFAIL\033[0m"
fi
done
}
function install {
for FILE in ${FILES[@]}; do
printf "Linking $FILE..."
TARGET=$HOME/$FILE
ln -s $DOTFILES_DIR/$FILE $TARGET
echo "done"
done
}
function rm_if_link(){ [ ! -L "$1" ] || rm -v "$1"; }
function uninstall {
for FILE in ${FILES[@]}; do
printf "Unlinking $FILE..."
TARGET=$HOME/$FILE
rm_if_link $TARGET > /dev/null
echo "done"
done
}
function print_help {
echo "Usage: $0 <command>"
echo ""
echo "Commands:"
echo "install"
echo -e "\tInstalls all dotfiles by linking them to their correct path"
echo ""
echo "uninstall"
echo -e "\tRemove all linked dotfiles"
echo ""
echo "health"
echo -e "\tChecks if all symlinks are correctly set"
}
case $1 in
install)
install
;;
uninstall)
uninstall
;;
health)
healthcheck
;;
*)
print_help
;;
esac