-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_or_update.sh
More file actions
executable file
·171 lines (153 loc) · 6.04 KB
/
install_or_update.sh
File metadata and controls
executable file
·171 lines (153 loc) · 6.04 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
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env zsh
set -euo pipefail
function notice {
echo "$(tput setaf 6)--> $(tput sgr0) $@"
}
function section {
tput setaf 6
echo ----------------------------------------------------------------------------------
echo $@
tput sgr0
}
function warning {
tput bold
tput setaf 1
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo WARNING: $@
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
tput sgr0
}
if ! which stow >/dev/null; then
warning "GNU stow is required to proceed."
exit 1
fi
# ${o:a:h} is Zsh magic for directory where script resides
# 0 (path to script), :a (absolute path), :h (head (drop filename))
# See http://zsh.sourceforge.net/Doc/Release/Expansion.html#Modifiers
DOTFILES_DIR=${0:a:h}
# Install Prezto per https://github.com/kishansundar/zprezto
if [ ! -d "${ZDOTDIR:-$HOME}/.zprezto" ]; then
section Installing Prezto
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
else
section Updating Prezto
cd "${ZDOTDIR:-$HOME}/.zprezto"
# Work-around for Poetry installer dropping a completion into this repo
# (Will need to remove this if these are ever added to https://github.com/zsh-users/zsh-completions/tree/master/src)
find . -name '_poetry' -delete
git pull --ff-only
git submodule sync
git submodule update --init --recursive
if which poetry > /dev/null; then
poetry completions zsh > modules/completion/external/src/_poetry
fi
fi
section Linking Zsh RC files
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
# if target already exists and isn't equivalent to the link we want to create and isn't an override from the stows
# directory, then alert.
if [ -e "${ZDOTDIR:-$HOME}/.${rcfile:t}" ]; then
if [[ ! "${ZDOTDIR:-$HOME}/.${rcfile:t}" -ef $rcfile ]]; then
if [ ! -e ${DOTFILES_DIR}/stows/.${rcfile:t} ]; then
warning "${ZDOTDIR:-$HOME}/.${rcfile:t} already exists, will not create link to $rcfile.\nUnless this file is intentionally present, delete and re-run."
fi
fi
else
notice "Linking ${ZDOTDIR:-$HOME}/.${rcfile:t} -> $rcfile"
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
fi
done
# Remove stock .zshrc and .zpreztorc to enable stowing of custom one below.
rm "${ZDOTDIR:-$HOME}/.zshrc"
rm "${ZDOTDIR:-$HOME}/.zpreztorc"
# Install Prezto-Contrib per https://github.com/belak/prezto-contrib
if [ ! -d "${ZPREZTODIR:-$HOME/.zprezto}/contrib" ]; then
section Installing Prezto-Contrib
git clone --recurse-submodules https://github.com/belak/prezto-contrib contrib
else
section Updating Prezto-Contrib
cd "${ZPREZTODIR:-$HOME/.zprezto}/contrib"
git pull --ff-only
git submodule sync
git submodule update --init --recursive
fi
if [ ! -d "$HOME/.vim_runtime" ]; then
section Installing Ultimate vimrc
git clone https://github.com/amix/vimrc.git "$HOME/.vim_runtime"
# Enable persistent undo
mkdir -p "$HOME/.vim_runtime/temp_dirs/undodir"
chmod 700 "$HOME/.vim_runtime/temp_dirs/undodir"
else
section Updating Ultimate vimrc
cd "${ZDOTDIR:-$HOME}/.vim_runtime"
git pull --ff-only
python3 update_plugins.py
fi
cd "${ZDOTDIR:-$HOME}/.vim_runtime"
./install_awesome_vimrc.sh
if which tmux >/dev/null; then
# Install Tmux Plugin Manager per https://github.com/tmux-plugins/tpm
if [ ! -d "${ZDOTDIR:-$HOME}/.tmux/plugins/tpm" ]; then
section Installing Tmux Plugin Manager
git clone https://github.com/tmux-plugins/tpm "${ZDOTDIR:-$HOME}/.tmux/plugins/tpm"
else
section Updating Tmux Plugin Manager
cd "${ZDOTDIR:-$HOME}/.tmux/plugins/tpm"
git pull --ff-only
fi
else
section "tmux not installed; skipping Tmux Plugin Manager"
fi
# Make a symlink in $HOME to each of the .dotfiles in stows/
section Installing dotfiles.
if stow --version | grep 2.3.1 > /dev/null; then
notice "Detected stow version 2.3.1. Ignore spurious 'BUG in find_stowed_path?' warnings.\nSee https://github.com/aspiers/stow/issues/65"
fi
stow --override=".*" --verbose --restow --target=$HOME --dir="$DOTFILES_DIR" stows
if [ -d "$DOTFILES_DIR/local_$(hostname -s)" ]; then
notice "Using local overrides ($DOTFILES_DIR/local_$(hostname -s))"
stow --override=".*" --verbose --restow --target=$HOME --dir="$DOTFILES_DIR" "local_$(hostname -s)"
else
notice "No local overrides found ($DOTFILES_DIR/local_$(hostname -s))"
fi
if type tmux >/dev/null && tmux server-info 2>/dev/null; then
section Updating Tmux Plugins
tmux source ~/.tmux.conf
~/.tmux/plugins/tpm/bin/install_plugins
~/.tmux/plugins/tpm/bin/update_plugins all
else
section "tmux not installed or not running; skipping Tmux Plugin update"
fi
section "checking for required tools"
if ! type delta > /dev/null; then
warning delta not installed, git diffs will not work properly
fi
section "checking for optional tools"
declare -A TOOLS
TOOLS=( \
[bat]="Enhanced cat (https://github.com/sharkdp/bat)" \
[duf]="Enhanced df disk usage/free space report (https://github.com/muesli/duf)" \
[dust]="Enhanced du (https://github.com/bootandy/dust)" \
[eza]="Enhanced ls (https://github.com/eza-community/eza)" \
[fastfetch]="neofetch replacement (https://github.com/fastfetch-cli/fastfetch)" \
[fd]="Enhanced find (https://github.com/sharkdp/fd)" \
[fzf]="Fuzzy finder (https://github.com/junegunn/fzf)" \
[rg]="Enhanced grep (https://github.com/BurntSushi/ripgrep)" \
[viddy]="Enhanced watch (https://github.com/sachaos/viddy)" \
)
declare -A DEFAULTS
DEFAULTS=( [bat]=1 [fastfetch]=1 [eza]=1 [viddy]=1 )
# Iterate keys and values (https://superuser.com/a/1237504)
for TOOL DESC in "${(@kv)TOOLS}"; do
if type $TOOL > /dev/null; then
if [[ -v DEFAULTS[$TOOL] ]]; then
MSG=" and will be aliased as default"
else
MSG=""
fi
notice "${TOOL} (${DESC}) found${MSG}"
else
notice "${TOOL} (${DESC}) not installed"
fi
done