-
Notifications
You must be signed in to change notification settings - Fork 10
/
stowsym.sh
executable file
·81 lines (70 loc) · 1.93 KB
/
stowsym.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
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#
# Simple script that creates symbolic links with the `stow` command for all the
# configuration files on the repository for your system.
DIRS=`ls -l --time-style="long-iso" . | egrep '^d' | awk '{print $8}'`
# Creates symbolinc links to configuration files.
function create_symlinks() {
for DIR in $DIRS
do
if [[ "$DIR" != "assets" ]]; then
echo "stowing $DIR"
stow ${DIR}
fi
done
}
# Deletes symbolinc links to configuration files.
function delete_symlinks() {
for DIR in $DIRS
do
if [[ "$DIR" != "assets" ]]; then
echo "delete stowing $DIR"
stow -D ${DIR}
fi
done
}
# Checks if `stow` is installed.
function is_stow_installed() {
if ! which stow &> /dev/null; then
echo "You need to first install: stow" > /dev/stderr
exit 1
fi
}
# Documentation of the program.
function menu() {
echo "Written by: Terencio Agozzino (rememberYou)"
echo -e " Mail: [email protected]\n"
echo "stowsym: stowsym [iu]"
echo -e " Creates and deletes symbolic links with stow.\n"
echo " Options:"
echo " -i Installation of configuration files by creating symbolic links."
echo " -d Deletion of configuration files by removing symbolic links."
echo -e " -h Help to use the script.\n"
echo -e " By default, -h were specified.\n"
echo " Exit Status:"
echo " Returns 0 unless an invalid option is given or the current directory"
echo " cannot be read."
}
while [ "$1" != "" ]; do
case $1 in
-d | --delete )
is_stow_installed
echo -e "Deletion of symbolinc links to configuration files...\n"
delete_symlinks
echo -e "\nDone."
exit
;;
-i | --install )
is_stow_installed
echo -e "Creation of symbolic links to configuration files...\n"
create_symlinks
echo -e "\nDone."
exit
;;
-h | --help )
menu
exit
esac
shift
done
menu