-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport-configs
executable file
·89 lines (76 loc) · 1.75 KB
/
export-configs
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
#! /bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DRY=
[ "$1" = "-d" ] && DRY=true
source $DIR/lib.sh
if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "help" ]; then
cat <<EOF
$ export-configs
Export the dotfiles onto the local machine.
Which files will be exported is specified in 'mappings'.
Only groups in 'used-groups' will be applied though.
Flags:
-d: to dry-run without exporting anything
EOF
exit
fi
if [ -z "$DRY" ]; then
printf "Really overwrite local files? (y/N): "
read ans
if [ "$ans" != "y" ] && [ "$ans" != "Y" ]; then
exit 0
fi
fi
CATEGORY=""
function install-files {
IFS=$'\n'
for IN in $(cat /dev/stdin); do
# categories
[ ${IN:0:1} = "[" ] && {
IN="${IN%]*}"
IN="${IN##*\[}"
CATEGORY=$IN
[ $(grep -f $IN_USE_TMP <<< $CATEGORY ) ] && echo "## $CATEGORY"
continue
}
# category not in use
[ ! $(grep -f $IN_USE_TMP <<< $CATEGORY ) ] && continue
REPO="$BASE/$IN"
LOCAL="$HOME/$IN"
isRootFile "$IN" && {
REPO="$BASE/$(echo $IN | cut -c2-)"
LOCAL="$IN"
}
# directories
[ -d "$REPO" ] && {
copy-dir $REPO $LOCAL
continue
}
# files
[ -f "$REPO" ] && {
copy-file $REPO $LOCAL
continue
}
# commands
CMD=$(echo "$IN" | cut -d " " -f1)
REST=$(echo "$IN" | cut -d" " -f2-)
case $CMD in
create)
if isRootFile "$REST"; then
create-dir "$REST"
else
create-dir "$HOME/$REST"
fi;;
clean)
copy-dir "$BASE/$REST" "$HOME/$REST";; # don't clean local
run)
run-command $IN;;
*)
echo "skipped: $IN"
esac
done
}
cat $MAPPINGS |
grep -v "^#" |
grep -v "^\s*$" |
install-files