-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
install.zsh
executable file
·153 lines (135 loc) · 4.27 KB
/
install.zsh
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
#!/usr/bin/env zsh
{ # This ensures the entire script is downloaded.
set -eo pipefail
basedir="$HOME/.dotfiles"
bindir="$HOME/bin"
repourl="https://github.com/statico/dotfiles.git"
function symlink() {
src="$1"
dest="$2"
if [ -e "$dest" ]; then
if [ -L "$dest" ]; then
if [ ! -e "$dest" ]; then
echo "Removing broken symlink at $dest"
rm "$dest"
else
# Already symlinked -- I'll assume correctly.
return 0
fi
else
# Rename files with a ".old" extension.
echo "$dest already exists, renaming to $dest.old"
backup="$dest.old"
if [ -e "$backup" ]; then
echo "Error: "$backup" already exists. Please delete or rename it."
exit 1
fi
mv "$dest" "$backup"
fi
fi
ln -sf "$src" "$dest"
}
if ! which git >/dev/null ; then
echo "Error: git is not installed"
exit 1
fi
if [ -d "$basedir/.git" ]; then
echo "Updating dotfiles using existing git..."
cd "$basedir"
git pull --quiet --rebase origin main || exit 1
else
echo "Checking out dotfiles using git..."
rm -rf "$basedir"
git clone --quiet --depth=1 "$repourl" "$basedir"
fi
cd "$basedir"
echo "Updating common Zsh completions..."
rm -rf .zsh-completions ~/.zcompdump
git clone --quiet --depth=1 https://github.com/zsh-users/zsh-completions .zsh-completions
echo "Creating symlinks..."
for item in .* ; do
case "$item" in
.|..|.git)
continue
;;
*)
symlink "$basedir/$item" "$HOME/$item"
;;
esac
done
symlink "$basedir/.vim/vimrc" "$HOME/.vimrc"
symlink "$basedir/.vim/gvimrc" "$HOME/.gvimrc"
if [ "$(uname -s)" = "Darwin" ]; then
vscodepath="$HOME/Library/Application Support/Code/User"
vscodeplatform=mac
else
vscodepath="$HOME/.config/Code/User"
vscodeplatform=linux
fi
mkdir -p "$vscodepath"
symlink "$basedir/.vscode-$vscodeplatform.settings.json" "$vscodepath/settings.json"
symlink "$basedir/.vscode-$vscodeplatform.keybindings.json" "$vscodepath/keybindings.json"
symlink "$basedir/.vscode-snippets" "$vscodepath/snippets"
echo "Adding executables to ~/bin/..."
mkdir -p "$bindir"
for item in bin/* ; do
symlink "$basedir/$item" "$bindir/$(basename $item)"
done
if [ -n "$VSCODE_REMOTE_CONTAINERS_SESSION" ]; then
# We must be setting up a VS Code remote dev container, so I probably won't use Vim.
echo "VS Code remote environment detected. Skipping Vim setup."
else
echo "Setting up vim plugins..."
.vim/update.sh
fi
echo "Setting up git..."
if [ -n "$VSCODE_REMOTE_CONTAINERS_SESSION" ]; then
# VS Code won't add a .gitconfig if one already exists, so we need to put
# ours in a magical secondary location I found by reading the Git docs.
altdir="$HOME/.althome"
mkdir -p "$altdir/git"
echo "export XDG_CONFIG_HOME=\"$altdir\"" >>"$HOME/.zshlocal"
cp "$basedir/.gitconfig.base" "$altdir/git/config"
else
cp "$basedir/.gitconfig.base" "$HOME/.gitconfig"
fi
if which git-lfs >/dev/null 2>&1 ; then
git lfs install
fi
if which code >/dev/null 2>&1 ; then
echo "VS Code found. Configuring Git to use it."
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait --merge $REMOTE $LOCAL $BASE $MERGED'
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
fi
if which tmux >/dev/null 2>&1 ; then
echo "Setting up tmux..."
tpm="$HOME/.tmux/plugins/tpm"
if [ -e "$tpm" ]; then
pushd "$tpm" >/dev/null
git pull -q origin master
popd >/dev/null
else
git clone -q https://github.com/tmux-plugins/tpm "$HOME/.tmux/plugins/tpm"
fi
$tpm/scripts/install_plugins.sh >/dev/null
$tpm/scripts/clean_plugins.sh >/dev/null
$tpm/scripts/update_plugin.sh >/dev/null
else
echo "Skipping tmux setup because tmux isn't installed."
fi
postinstall="$HOME/.postinstall"
if [ -e "$postinstall" ]; then
echo "Running post-install..."
. "$postinstall"
else
echo "No post install script found. Optionally create one at $postinstall"
fi
if [ ! -e "$HOME/.zshlocal" ]; then
color=$((22 + RANDOM % 209))
echo -e "# If you want a different color, run ~/bin/256-colors.sh and replace $color below:\ncolorprompt \"38;5;$color\"" >"$HOME/.zshlocal"
echo "Chose a random prompt color. Edit $HOME/.zshlocal to change it."
fi
echo "Done."
} # This ensures the entire script is downloaded.