-
Notifications
You must be signed in to change notification settings - Fork 0
/
stow-config.sh
73 lines (61 loc) · 1.19 KB
/
stow-config.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
#!/usr/bin/env sh
mode='SYMLINK'
thing=''
# Check args for mode
while getops 'c' option; do
case "$option" in
c)
mode="COPY"
;;
esac
done
shift $((OPTIND - 1))
arg_iter=0
for arg in "$@"; do
arg_iter=$(expr $arg_iter + 1)
if [[ "$arg" == '--copy' ]]; then
mode='COPY'
arg_iter=0
break
fi
done
if [[ "$DOT" == '' ]]; then
echo 'Error: cannot stow anything until $DOT is set to DOTFILES location'
exit 1
elif [[ "$HOME" == '' ]]; then
echo 'Error: cannot stow anything until $HOME is set'
exit 1
fi
if [[ "$arg_iter" == '0' ]]; then
thing="$1"
else
# assume
thing="$2"
fi
thing_in() {
thing="$1"
arr="$2"
for name in "${arr[@]}"; do
if [[ "$thing" == "$name" ]]; then
return 1
fi
done
return 0
}
stow_it() {
src="$1"
dest="$2"
if [[ "$mode" == 'COPY' ]]; then
# -v verbose, -R restow(overwrite sym), -t dest dir
stow -v -R -t "${HOME}/${dest}" "${DOT}/${src}"
else
cp -r "${DOT}/${src}" "${HOME}/${dest}"
fi
}
if [[ $(thing_in "$thing" ('neovim' 'nvim' 'nv')) ]]; then
stow_it 'config/nvim' '.config/'
elif [[ "$thing" == 'alacritty' ]]; then
stow_it 'config/alacritty' '.config/'
elif [[ "$thing" == 'tmux' ]]; then
stow_it 'config/tmux' '.config/'
fi