-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·49 lines (44 loc) · 920 Bytes
/
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
#!/usr/bin/env bash
set -euo pipefail
function helptext() {
cat <<EOH
Usage: $0 [OPTS] [DIR...]
OPTS:
-f Force overwrites
-h Help
EOH
}
FORCE=
SEARCH=()
# FIXME
while getopts "hf" o; do case $o in
h) helptext; exit 0 ;;
f) FORCE=1 ;;
*) SEARCH+=("$OPTARG");;
esac done
shift $((OPTIND-1))
SEARCH+=("$@")
if [ $# -eq 0 ]; then
SEARCH=('.')
fi
find "${SEARCH[@]}" -name loc | while read -r loc; do
fromdir="$(dirname "$loc")"
while read -r line; do
from="$fromdir/$(cut -d' ' -f1 <<<"$line")"
to="${line##* }"
if [ -e "$HOME/$to" ]; then
if [ -z "$FORCE" ]; then
echo "error: ~/$to already exists" >&2
echo "to overwrite existing files run with -f" >&2
exit 1
else
# shellcheck disable=SC2115
rm -rf "$HOME/$to"
fi
fi
# shellcheck disable=SC2088
echo "~/$to <- $from"
mkdir -p "$(dirname "$HOME/$to")"
ln -fns "$(realpath "$from")" "$HOME/$to"
done <"$loc"
done