-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.sh
executable file
·46 lines (40 loc) · 1.25 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
#!/usr/bin/env bash
# allow globs to see dotfiles
shopt -s dotglob
# get reference to script directory as starting point
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# suppress echos from pushd and popd for clean output
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd > /dev/null
}
# recursive loop over files, creating mirrored directories and linking
# only files. Avoids accidentally adding new files to dotfiles repo
# if they are created and inserted into a symlinked directory later
tryfiles () {
local path="$1"
if [ -d "${DIR}/${path}" ]; then
pushd "${DIR}/${path}" || return
mkdir -p "${HOME}/${path}"
for f in *; do
local newpath="${path}/${f}"
tryfiles "${newpath}"
done
popd || return
else
if [ -e "${HOME}/${path}" ]; then
printf "File Exists, Skipping: %s\\n" "${HOME}/${path}"
else
ln -sfn "${DIR}/${path}" "$HOME/${path}"
printf "Linking: %s/%s\\n" "${DIR}" "${path}"
fi
fi
}
# main loop, ignoring some key files
for x in *; do
if [ "$x" != ".git" ] &&[ "$x" != ".gitignore" ] && [ "$x" != "." ] && [ "$x" != ".." ] && [ "$x" != "install.sh" ]&& [ "$x" != "uninstall.sh" ] && [ "$x" != "README.md" ]; then
tryfiles "$x"
fi
done