-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.sh
executable file
·151 lines (125 loc) · 4 KB
/
setup.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh
set -e
# -- Global variables --
CONFIG_DIR=$(cd "$(dirname $0)"; pwd)
cd
OS_NAME=$(uname)
STAMP=$(date +%Y%m%dT%H%M%S)
# -- Functions --
# Clears away the given file, backing it up first if needed.
# If it is a real file (not a symlink), it is renamed.
# Or if the file is a symlink, it is simply deleted.
clear_file() {
f="$1"
if [ -h "$f" ]; then
(set -x; rm "$f")
elif [ -f "$f" ]; then
bk="$f.$STAMP"
(set -x; mv "$f" "$bk")
fi
}
# Copies the given source to the specified destination.
# Does nothing if files match; otherwise, replaces the original file.
install_file() {
src="$1"
dest="$2"
diff "$src" "$dest" > /dev/null 2>&1 ||
(clear_file "$dest"; set -x; cp "$src" "$dest")
}
# Symlinks the given source to the specified destination.
link_file() {
src="$1"
dest="$2"
clear_file "$dest"
(set -x; ln -s "$src" "$dest")
}
# -- Main --
echo
echo "--> Linking up your dotfiles..."
# ~/.bashrc
# NB: We use a stub for .bashrc to maintain support for systems that
# do not support proper symlinks -- especially MSysGit on Windows.
BASHRC_STUB="$CONFIG_DIR/bashrc.stub"
echo "export DOTFILES=\"$CONFIG_DIR\"" > "$BASHRC_STUB"
echo '. "$DOTFILES/bashrc"' >> "$BASHRC_STUB"
install_file "$BASHRC_STUB" .bashrc
rm -f "$BASHRC_STUB"
# ~/.zshrc
# NB: We use a stub for .zshrc to maintain support for systems that
# do not support proper symlinks -- especially MSysGit on Windows.
ZSHRC_STUB="$CONFIG_DIR/zshrc.stub"
echo "export DOTFILES=\"$CONFIG_DIR\"" > "$ZSHRC_STUB"
echo 'source "$DOTFILES/zshrc"' >> "$ZSHRC_STUB"
install_file "$ZSHRC_STUB" .zshrc
rm -f "$ZSHRC_STUB"
# ~/.gitconfig
# NB: We use a stub for .gitconfig so that it can be extended with a
# [user] section without causing git to see the gitconfig here as dirty.
GITCONFIG_STUB="$CONFIG_DIR/gitconfig.stub"
echo '[include]' > "$GITCONFIG_STUB"
printf "\tpath = $CONFIG_DIR/gitconfig\n" >> "$GITCONFIG_STUB"
install_file "$GITCONFIG_STUB" .gitconfig
rm -f "$GITCONFIG_STUB"
# ~/.ssh/config
# NB: We write out a starter .ssh/config so that it can be extended with
# additional configuration without causing git to see the file as dirty.
SSHCONFIG=.ssh/config
if [ ! -f "$SSHCONFIG" ]
then
mkdir -p .ssh
for f in "$CONFIG_DIR/ssh.d"/*
do
(set -x; echo "Include $f" >> "$SSHCONFIG")
done
fi
# ~/.bash_profile
link_file "$CONFIG_DIR/bash_profile" .bash_profile
# ~/.jgorc
link_file "$CONFIG_DIR/jgorc" .jgorc
# ~/.mrconfig
link_file "$CONFIG_DIR/mrconfig" .mrconfig
# ~/.config/mr
mkdir -p .config/mr
link_file "$CONFIG_DIR/mrconfig.d/essential" .config/mr/essential
# ~/.config/wd
mkdir -p .config/wd
link_file "$CONFIG_DIR/warprc" .config/wd/warprc
# ~/.vim/vimrc
mkdir -p .vim
link_file "$CONFIG_DIR/vimrc" .vim/vimrc
# ~/.XCompose
link_file "$CONFIG_DIR/XCompose" .XCompose
# ~/bin
# NB: It's OK if the sources don't exist yet, or ever.
# This step just makes them available on the path,
# in case they do get cloned locally into ~/code.
mkdir -p bin
link_file "../code/git/git-diff-blame/git-diff-blame" bin/git-diff-blame
link_file "../code/git/git-recover/git-recover" bin/git-recover
link_file "../code/scijava/jgo/jgo.sh" bin/jgo
link_file "../code/util/icat/icat" bin/icat
# ~/Library/KeyBindings [macOS]
case "$(uname)" in
Darwin)
cd Library
link_file "$CONFIG_DIR/KeyBindings" KeyBindings
cd ..
;;
esac
echo
echo "--> Personalizing your experience..."
cat "$CONFIG_DIR/old-man.txt"
echo "Answer me these questions three, ere the other side ye see!"
printf "What... is your full name? "
read committer_name
printf "What... is your email address? "
read committer_email
echo "What... is the airspeed velocity of an unladen --"
echo "The people responsible for this shell script have been sacked."
(set -x; git config --global user.name "$committer_name")
(set -x; git config --global user.email "$committer_email")
(clear_file .forward; set -x; echo "$committer_email" > .forward)
# ~/.plan
test "$committer_name" = "Curtis Rueden" && link_file "$CONFIG_DIR/plan" .plan
echo
echo "--> Done! Now open a new terminal. :-)"