-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-dotfiles
executable file
·98 lines (84 loc) · 1.95 KB
/
install-dotfiles
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
#!/bin/sh
# -*- ksh -*-
set -euf
# files containing this string in the first 3 lines will
# be left alone.
save="install-dotfiles-preserve"
# on my shiny new Mac, /bin/sh doesn't honor the -n flag
# this is why we can't have nice things
echon () {
/bin/echo -n "$@"
}
if [ -z "$HOME" ]; then
echo "\$HOME not set. I can't guess where you hid the git repository."
exit 1
fi
cvsdir=''
for dir in "$HOME"/git/dotfiles "$(pwd)" ; do
if [ -z "$cvsdir" ] && [ -d "$dir" ]; then
cvsdir="$dir"
echo "repository dotfiles directory is $cvsdir"
fi
done
if [ -z "$cvsdir" ]; then
echo "Unable to deduce the repository."
exit 0
fi
cd "${HOME}"
# /bin/ls -1 | egrep -v '^(README.md|CVS|install-dotfiles)$' | sed 's/$/ \\/'
for dotfile in \
Xresources \
bash_profile \
bashrc \
gdbinit \
gitconfig \
git-global-ignore \
guile \
inputrc \
screenrc \
tcshrc \
tmux.conf \
zprofile \
zshrc \
; do
echon "${dotfile}: "
# 0. Check for override; ignore if so
if test -e ."$dotfile" ; then
if head -3 ."$dotfile" | grep -q "$save" ; then
echo "exists, and is marked to keep; skip."
continue
fi
fi
# 1. blow away old links
# -L is a link on bash; -h is on FreeBSD /bin/sh?
# -h seems to work on bash
if [ -h ".${dotfile}" ]; then
echon "removing old link, "
rm ".${dotfile}"
fi
# 2. move aside old file
if [ -e ".${dotfile}" ]; then
echon "moving file to ${dotfile}.old, "
mv ".$dotfile" "${dotfile}.old"
fi
# 3. install new link
echon "installing link, "
ln -s "$cvsdir/$dotfile" ".$dotfile"
if test "#!" = "$(head -1 "$cvsdir/$dotfile" | cut -c1-2)" ; then
echon "making executable, "
chmod +x "$cvsdir/$dotfile"
fi
echo "done."
done
for f in \
emacs \
; do
echon "$f: "
if [ -f ".$f" ]; then
echon "found unwanted file, moving to $f.old, "
mv ".$f" "${f}".old
echo done.
else
echo "no old file found."
fi
done