-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·159 lines (133 loc) · 4.45 KB
/
setup.sh
File metadata and controls
executable file
·159 lines (133 loc) · 4.45 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
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
152
153
154
155
156
157
158
159
#!/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"
case "$(uname)" in
# Note: We cannot use `ln -s` nor `mklink` due to Windows
# restricting creation of symbolic links by default.
# And we can only hard link a file that actually exists.
MINGW*) test ! -f "$src" || (set -x; ln "$src" "$dest") ;;
*) (set -x; ln -sf "$src" "$dest") ;;
esac
}
# -- Main --
echo
echo "--> Linking up your dotfiles..."
# NB: We use stub files for some shell config files, to maintain support for
# systems that do not support proper symlinks -- especially MSysGit on Windows.
# It also enables command-line tools such as conda to mess with these
# files as they desire without dirtying the dotfiles working copy.
# ~/.bashrc
for cfgFile in bashrc bash_profile zshrc
do
tmpFile="$CONFIG_DIR/$cfgFile.stub"
rm -f "$tmpFile"
if [ "$cfgFile" = "bashrc" ]; then
# Bash interactive guard: prevent non-interactive sessions (e.g., gdm3 login)
# from sourcing bashrc, which would leak exports into the X session environment.
echo '[ -z "$PS1" ] && return # Continue only if shell is interactive.' >> "$tmpFile"
fi
echo "export DOTFILES=\"$CONFIG_DIR\"" >> "$tmpFile"
echo ". \"\$DOTFILES/$cfgFile\"" >> "$tmpFile"
install_file "$tmpFile" ".$cfgFile"
rm -f "$tmpFile"
done
# ~/.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
# ~/.config/starship.toml
link_file "$CONFIG_DIR/starship.toml" .config/starship.toml
# ~/.config/jgo.conf
link_file "$CONFIG_DIR/jgo.conf" .config/jgo.conf
# ~/.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/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. :-)"