-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.sh
executable file
·68 lines (55 loc) · 864 Bytes
/
manage.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
files=(\
bash_profile
bashrc \
ctags\
vimrc \
git_template \
gitconfig \
)
die() {
echo "Usage: ./manage.sh {create|remove}"
exit 1
}
new_path() {
echo "$HOME/.$1"
}
create_link() {
local filename="$1"
if [[ ! -e "$filename" ]]; then
echo "$filename doesn't exist"
return
fi
target="$(new_path "$filename")"
if [[ ! -e "$target" ]]; then
echo "Linking $filename to $target"
ln -s "$PWD/$filename" "$target"
fi
}
create_links() {
for file in "${files[@]}"
do
create_link "$file"
done
}
remove_link() {
target="$(new_path "$1")"
if [ -e "$target" ]; then
echo "Removing $target"
rm "$target"
fi
}
remove_links() {
for file in "${files[@]}"
do
remove_link "$file"
done
}
if [[ $# != 1 ]]; then
die
fi
if [[ $1 == "create" ]]; then
create_links
elif [[ $1 == "remove" ]]; then
remove_links
fi