-
Notifications
You must be signed in to change notification settings - Fork 0
/
stow.sh
executable file
·105 lines (85 loc) · 1.99 KB
/
stow.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
# Inspired by https://github.com/NeshHari/XMonad
show_help() {
echo "Usage: $(basename $0) [-v] [-C] [-h]"
echo " -C: Stow the common configuration files only"
echo " -v: Show verbose messages"
echo " -h: Show this help message"
}
while getopts ':vC' OPTION; do
case "$OPTION" in
v)
VERBOSE=1
;;
C)
COMMON_ONLY=1
;;
h)
show_help
exit 0
;;
?)
show_help
exit 1
;;
esac
done
shift "$(( $OPTIND - 1 ))"
debug() {
if [ -n $VERBOSE ]; then
echo $1
fi
}
stow_package() {
package=$1
stowignore="./$package/.stowignore"
ignored_dirs=()
stow_dirs=()
verbose_stow=""
if [ -n $VERBOSE ]; then
verbose_stow="-v"
fi
if [ -f $stowignore ]; then
while IFS= read -r line; do
ignored_dirs+=($line)
done < $stowignore
fi
for dir in $package/*; do
if [ ! -d "$dir" ]; then
continue
fi
if echo ${ignored_dirs[@]} | grep -q -w "$dir"; then
debug "Skipping $dir.."
continue
fi
if ! stow -d "$package" -t $HOME "$verbose_stow" $(basename $dir); then
stow_dirs+=($dir)
fi
done
if [ ${#stow_dirs[@]} -gt 0 ]; then
echo "The following $platform directories could not be stowed: ${stow_dirs[@]}"
echo "Please manually copy the respective configs."
fi
}
stow_package "common"
if [ -z $COMMON_ONLY ]; then
PLATFORM="$1"
if [ -z "$PLATFORM" ]; then
agent=$(uname)
case $agent in
Linux)
PLATFORM="arch"
debug "Using 'arch' as a default.."
;;
Darwin)
PLATFORM="macos"
debug "Using 'macos' as a default.."
;;
*)
echo "Please provide a platform"
exit 1
;;
esac
fi
stow_package "$PLATFORM"
fi