-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall
More file actions
executable file
·100 lines (82 loc) · 2.01 KB
/
install
File metadata and controls
executable file
·100 lines (82 loc) · 2.01 KB
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
#!/usr/bin/env bash
set -e
test -z "${DEBUG}" || set -x
##
# directory context
pushd "$(dirname "$0")" > /dev/null
root=$(pwd)
popd > /dev/null
##
##
# parameters
opts="b:Dh"
backup=""
function usage {
cat << _usage_
$(basename "$0"): install cli symlinks to \$HOME
usage:
$(basename "$0") [-$opts]
b <ext> - backup existing files with extension (e.g. -b .bak).
D - turn on debug mode.
h - you are here.
note:
gitconfig is not installed by this script (copy and edit manually).
_usage_
}
while getopts $opts opt; do
case $opt in
b) backup="$OPTARG" ;;
D) DEBUG=true; set -x ;;
h) usage; exit ;;
?|*) echo; usage; exit 5 ;;
esac
done
shift $((OPTIND-1))
##
##
# link: create a symlink idempotently
# link <source> <target>
function link {
local src="$1"
local target="$2"
if test -L "$target"; then
local current
current=$(readlink "$target")
if test "$current" = "$src"; then
echo " skip: $target (already linked)"
return
fi
fi
if test -e "$target"; then
if test -n "$backup"; then
echo " backup: $target → ${target}${backup}"
cp -a "$target" "${target}${backup}"
else
echo " warn: $target exists (use -b to backup)" >&2
return
fi
fi
local targetDir
targetDir=$(dirname "$target")
test -d "$targetDir" || mkdir -p "$targetDir"
ln -sf "$src" "$target"
echo " link: $target → $src"
}
##
##
# main
echo "installing cli from $root"
link "$root/bashrc" "$HOME/.bashrc"
link "$root/inputrc" "$HOME/.inputrc"
link "$root/psqlrc" "$HOME/.psqlrc"
link "$root/hushlogin" "$HOME/.hushlogin"
link "$root/gitignore" "$HOME/.gitignore"
link "$root/vi/exrc" "$HOME/.exrc"
link "$root/vi/vimrc" "$HOME/.vimrc"
link "$root/vi/vimrc" "$HOME/.ideavimrc"
link "$root/vi/colors/colors" "$HOME/.vim/colors"
echo "done."
echo ""
echo "note: copy and edit gitconfig manually:"
echo " cp $root/gitconfig ~/.gitconfig"
##