-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·58 lines (47 loc) · 1.53 KB
/
install.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
#!/usr/bin/env bash
#
# Installs the dotfiles into the user's home directory.
#
# NOTE: the bash dotfiles assume a layout of ~/dotfiles
set -eo pipefail
# Directory in which this script is located.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
handle() {
source="$1"
filename="${source##*/}"
if [ "$filename" == "dotfiles" ]; then return; fi
if [ -z "$filename" ]; then return; fi
target="$HOME/$filename"
# We could use `ln -i` to prompt user if the target file exists
# but it doesn't take account of the target being what we want anyway.
if [ -e "$target" ]; then
if [ "$(readlink "$target")" = "$source" ]; then
echo skip: "$source" → "$target"
else
read -r -n 1 -p "overwrite $target (y/n)? " answer
echo
case "$answer" in
y|Y)
# I can't get -nF to remove target when it is a directory.
# So manually remove instead.
rm -r "$target" && ln -s "$source" "$target" && echo link: "$source" → "$target"
;;
*)
echo skip: "$source"
;;
esac
fi
else
ln -s "$source" "$target" && echo link: "$source" → "$target"
fi
}
# Instead of listing filenames and then reading the list,
# just execute something for each file.
export -f handle
find "$DIR" -maxdepth 1 \
-not -name .DS_Store \
-not -name .git \
-not -name bash \
-not -name README.md \
-not -name install.sh \
-exec bash -c 'handle "$0"' {} \;