-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·135 lines (124 loc) · 3.08 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
symlink() {
ln -s "$1" "$2"
echo "Linked '$1' to '$2'"
}
maybe_symlink_file() {
echo -n " Backup & replace, Replace, View, Skip, Abort? (b/r/v/s/a) "
read -r answer
case $answer in
b|B) mv "$2" "$2.bak"
symlink "$1" "$2"
;;
r|R) rm "$2"
symlink "$1" "$2"
;;
v|V) less "$2"
maybe_symlink_file "$1" "$2"
;;
s|S) # Do nothing
echo "Skipped"
;;
a|A) exit 0
;;
*) echo " Unknown selection"
maybe_symlink_file "$1" "$2"
;;
esac
}
maybe_symlink_directory() {
echo -n " Backup & replace, Replace, View, Skip, Abort? (b/r/v/s/a) "
read -r answer
case $answer in
b|B) mv "$2" "$2.bak"
symlink "$1" "$2"
;;
r|R) rm -r "$2"
symlink "$1" "$2"
;;
v|V) ls "$2"
maybe_symlink_directory "$1" "$2"
;;
s|S) # Do nothing
echo "Skipped"
;;
a|A) exit 0
;;
*) echo " Unknown selection"
maybe_symlink_directory "$1" "$2"
;;
esac
}
maybe_symlink_symlink() {
echo -n " Replace, View, Skip, Abort? (r/v/s/a) "
read -r answer
case $answer in
r|R) rm "$2"
symlink "$1" "$2"
;;
v|V) ls -l "$2"
maybe_symlink_symlink "$1" "$2"
;;
s|S) # Do nothing
echo "Skipped"
;;
a|A) exit 0
;;
*) echo " Unknown selection"
maybe_symlink_symlink "$1" "$2"
;;
esac
}
maybe_symlink() {
echo -n "Link '$1' to '$2'? (y/n) "
read -r answer
case $answer in
y) if [ -h "$2" ]; then
echo "'$2' is already a SYMLINK."
maybe_symlink_symlink "$1" "$2"
elif [ -f "$2" ]; then
echo "'$2' is already a FILE."
maybe_symlink_file "$1" "$2"
elif [ -d "$2" ]; then
echo "'$2' is already a DIRECTORY."
maybe_symlink_directory "$1" "$2"
else
symlink "$1" "$2"
fi
echo # Blank line for readability
;;
n) echo "Skipped"
echo # Blank line for readability
;;
*) echo " Unknown selection"
maybe_symlink "$1" "$2"
;;
esac
}
link_home() {
target="$2"
if [ -z "$target" ]; then
target=".$(basename "$1")"
fi
maybe_symlink "$PWD/$1" "$HOME/$target"
}
# Scripts directory
link_home bin bin
# Bash
link_home bash/bashrc
link_home bash/bash_profile
# Git
link_home git/gitconfig
link_home git/gitignore
case $(uname -s) in
Linux) link_home git/gitconfig.linux .gitconfig.os ;;
Darwin) link_home git/gitconfig.macos .gitconfig.os ;;
*) echo "Unknown OS; skipping .gitconfig.os" ;;
esac
# Vim
link_home vim/vimrc
# Miscellaneous
link_home bash/inputrc
link_home misc/hushlogin
link_home misc/shellcheckrc
link_home misc/rgignore