forked from unixorn/zsh-quickstart-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zgen-setup
318 lines (265 loc) · 10.6 KB
/
.zgen-setup
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/usr/bin/env zsh
#
# Only including a shebang to trigger editors to use shell
# syntax highlighting.
#
# Copyright 2006-2022 Joseph Block <[email protected]>
#
# BSD licensed, see LICENSE.txt
# Clone zgenom if you haven't already
if [[ -z "$ZGENOM_PARENT_DIR" ]]; then
ZGENOM_PARENT_DIR=$HOME
ZGENOM_SOURCE_FILE=$ZGENOM_PARENT_DIR/.zqs-zgenom/zgenom.zsh
# Set ZGENOM_SOURCE_FILE to the old directory if it already exists
if [[ -f "$ZGENOM_PARENT_DIR/zgenom/zgenom.zsh" ]] ; then
ZGENOM_SOURCE_FILE=$ZGENOM_PARENT_DIR/zgenom/zgenom.zsh
fi
fi
# zgenom stores the clones plugins & themes in $ZGEN_DIR when it
# is set. Otherwise it stuffs everything in the source tree, which
# is unclean.
ZGEN_DIR=${ZGEN_DIR:-$HOME/.zgenom}
if [[ ! -f "$ZGENOM_SOURCE_FILE" ]] ; then
if [[ ! -d "$ZGENOM_PARENT_DIR" ]]; then
mkdir -p "$ZGENOM_PARENT_DIR"
fi
pushd $ZGENOM_PARENT_DIR
git clone https://github.com/jandamm/zgenom.git .zqs-zgenom
popd
fi
if [[ ! -f "$ZGENOM_SOURCE_FILE" ]] ; then
echo "Can't find zgenom.zsh"
else
# echo "Loading zgenom"
source "$ZGENOM_SOURCE_FILE"
fi
unset ZGENOM_PARENT_DIR ZGENOM_SOURCE_FILE
warn-about-prompt-change() {
if [[ ! -f ~/.zsh-quickstart-kit-prompt-switch-warning ]]; then
echo
echo "The default ZSH prompt in the quickstart kit has changed from"
echo "bullet-train to powerlevel10k."
echo
echo "If you want to use the old prompt, run zsh-quickstart-select-bullet-train"
echo
echo "Run zsh-quickstart-select-powerlevel10k to switch to the new prompt"
echo
echo "If you do nothing, you will be switched to powerlevel10k"
echo
touch ~/.zsh-quickstart-kit-prompt-switch-warning
fi
}
load-starter-plugin-list() {
echo "Creating a zgenom save"
ZGEN_LOADED=()
ZGEN_COMPLETIONS=()
if [[ ! -f ~/.zsh-quickstart-no-omz ]] || [[ $(_zqs-get-setting load-omz-plugins true) == 'true' ]]; then
zgenom oh-my-zsh
fi
# If you want to customize your plugin list, create a file named
# .zsh-quickstart-local-plugins-example in your home directory. That
# file will be sourced during startup *instead* of running this
# load-starter-plugin-list function, so make sure to include everything
# from this function that you want to keep.
#
# To make customizing easier, there's a .zsh-quickstart-local-plugins-example
# file at the top level of the zsh-quickstart-kit repository that you can
# copy as a starting point. This keeps you from having to maintain a fork of
# the quickstart kit.
# If zsh-syntax-highlighting is bundled after zsh-history-substring-search,
# they break, so get the order right.
zgenom load zdharma-continuum/fast-syntax-highlighting
zgenom load zsh-users/zsh-history-substring-search
# Set keystrokes for substring searching
zmodload zsh/terminfo
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
# Tab complete rakefile targets.
zgenom load unixorn/rake-completion.zshplugin
# Automatically run zgenom update and zgenom selfupdate every 7 days.
zgenom load unixorn/autoupdate-zgenom
# Add my collection of miscellaneous utility functions.
zgenom load unixorn/jpb.zshplugin
# Colorize the things if you have grc installed. Well, some of the
# things, anyway.
zgenom load unixorn/warhol.plugin.zsh
# macOS helpers. This plugin is smart enough to detect when it isn't running
# on macOS and not load itself, so you can safely share the same plugin list
# across macOS and Linux/BSD.
zgenom load unixorn/tumult.plugin.zsh
# Warn you when you run a command that you've set an alias for without
# using the alias.
zgenom load djui/alias-tips
# Add my collection of git helper scripts.
zgenom load unixorn/git-extra-commands
# Supercharge your history search with fzf
zgenom load unixorn/fzf-zsh-plugin
# Add my bitbucket git helpers plugin.
zgenom load unixorn/bitbucket-git-helpers.plugin.zsh
# A collection of scripts that might be useful to sysadmins.
zgenom load skx/sysadmin-util
# Adds aliases to open your current repo & branch on github.
zgenom load peterhurford/git-it-on.zsh
# Tom Limoncelli's tooling for storing private information (keys, etc)
# in a repository securely by encrypting them with gnupg.
zgenom load StackExchange/blackbox
if [[ -f ~/.zqs-add-plugins ]]; then
source ~/.zqs-add-plugins
fi
if [[ -d ~/.zshrc.add-plugins.d ]]; then
load-shell-fragments ~/.zshrc.add-plugins.d
fi
if [[ ! -f ~/.zsh-quickstart-no-omz ]] || [[ $(_zqs-get-setting load-omz-plugins false) == 'true' ]]; then
# Load some oh-my-zsh plugins
zgenom oh-my-zsh plugins/pip
zgenom oh-my-zsh plugins/sudo
zgenom oh-my-zsh plugins/aws
zgenom oh-my-zsh plugins/chruby
zgenom oh-my-zsh plugins/colored-man-pages
zgenom oh-my-zsh plugins/git
zgenom oh-my-zsh plugins/github
zgenom oh-my-zsh plugins/python
zgenom oh-my-zsh plugins/rsync
zgenom oh-my-zsh plugins/screen
zgenom oh-my-zsh plugins/vagrant
if [ $(uname -a | grep -ci Darwin) = 1 ]; then
# Load macOS-specific plugins
zgenom oh-my-zsh plugins/brew
zgenom oh-my-zsh plugins/macos
fi
fi
# A set of shell functions to make it easy to install small apps and
# utilities distributed with pip.
zgenom load sharat87/pip-app
zgenom load chrissicool/zsh-256color
# Load more completion files for zsh from the zsh-lovers github repo.
zgenom load zsh-users/zsh-completions src
# Docker completion
zgenom load srijanshetty/docker-zsh
# Load tab completions for 1Password's op command line tool if it's installed
zgenom load unixorn/1password-op.plugin.zsh
# Load me last
GENCOMPL_FPATH=$HOME/.zsh/complete
# Very cool plugin that generates zsh completion functions for commands
# if they have getopt-style help text. It doesn't generate them on the fly,
# you'll have to explicitly generate a completion, but it's still quite cool.
zgenom load RobSis/zsh-completion-generator
# Add Fish-like autosuggestions to your ZSH.
zgenom load zsh-users/zsh-autosuggestions
# k is a zsh script / plugin to make directory listings more readable,
# adding a bit of color and some git status information on files and
# directories.
zgenom load supercrabtree/k
# Be compatible with the old settings files for now
if [[ -f ~/.zsh-quickstart-use-bullet-train ]] || [[ $(_zqs-get-setting bullet-train false) == 'true' ]]; then
# Bullet train prompt setup.
zgenom load https://github.com/caiogondim/bullet-train.zsh
else
# p10k is faster and what I'm using now, so it is the new default
zgenom load romkatv/powerlevel10k powerlevel10k
warn-about-prompt-change
fi
# Save it all to init script.
zgenom save
}
setup-zgen-repos() {
ZQS_override_plugin_list=''
# Check the old name for backward compatibility
if [[ -r $HOME/.zgen-local-plugins ]]; then
ZQS_override_plugin_list="$HOME/.zgen-local-plugins"
fi
# If they have both, the new name takes precedence
if [[ -r $HOME/.zsh-quickstart-local-plugins ]]; then
ZQS_override_plugin_list="$HOME/.zsh-quickstart-local-plugins"
fi
if [[ -r "$ZQS_override_plugin_list" ]]; then
echo "Loading local plugin list from $ZQS_override_plugin_list"
source "$ZQS_override_plugin_list"
unset ZQS_override_plugin_list
else
load-starter-plugin-list
fi
}
# This comes from https://stackoverflow.com/questions/17878684/best-way-to-get-file-modified-time-in-seconds
# This works on both Linux with GNU fileutils and macOS with BSD stat.
# Naturally BSD/macOS and Linux can't share the same options to stat.
if [[ $(uname | grep -ci -e Darwin -e BSD) = 1 ]]; then
# macOS version.
get_file_modification_time() {
modified_time=$(stat -f %m "$1" 2> /dev/null) || modified_time=0
echo "${modified_time}"
}
elif [[ $(uname | grep -ci Linux) = 1 ]]; then
# Linux version.
get_file_modification_time() {
modified_time=$(stat -c %Y "$1" 2> /dev/null) || modified_time=0
echo "${modified_time}"
}
fi
# check if there's an init.zsh file for zgen and generate one if not.
if ! zgen saved; then
setup-zgen-repos
fi
# Our installation instructions get the user to make a symlink
# from ~/.zgen-setup to wherever they checked out the zsh-quickstart-kit
# repository.
#
# Unfortunately, stat will return the modification time of the
# symlink instead of the target file, so construct a full path to hand off
# to stat so it returns the modification time of the actual .zgen-setup file.
if [[ -f ~/.zgen-setup ]]; then
REAL_ZGEN_SETUP=~/.zgen-setup
fi
if [[ -L ~/.zgen-setup ]]; then
REAL_ZGEN_SETUP="$(readlink ~/.zgen-setup)"
fi
# If you don't want my standard starter set of plugins, create a file named
# .zsh-quickstart-local-plugins and add your zgenom load commands there. Don't forget to
# run `zgenom save` at the end of your .zsh-quickstart-local-plugins file.
#
# Warning: .zgen-local-plugins REPLACES the starter list setup, it doesn't
# add to it.
#
# Use readlink in case the user is symlinking from another repo checkout, so
# they can use a personal dotfiles repository cleanly.
if [[ -f ~/.zgen-local-plugins ]]; then
REAL_ZGEN_SETUP=~/.zgen-local-plugins
fi
if [[ -L ~/.zgen-local-plugins ]]; then
REAL_ZGEN_SETUP="${HOME}/$(readlink ~/.zgen-local-plugins)"
fi
# Old file still works for backward compatibility, but we want the new file
# to take precedence when both exist.
if [[ -f ~/.zsh-quickstart-local-plugins ]]; then
REAL_ZGEN_SETUP=~/.zsh-quickstart-local-plugins
fi
if [[ -L ~/.zsh-quickstart-local-plugins ]]; then
REAL_ZGEN_SETUP="${HOME}/$(readlink ~/.zsh-quickstart-local-plugins)"
fi
# If .zgen-setup is newer than init.zsh, regenerate init.zsh
if [ $(get_file_modification_time ${REAL_ZGEN_SETUP}) -gt $(get_file_modification_time ~/.zgenom/init.zsh) ]; then
echo "$(basename ${REAL_ZGEN_SETUP}) ($REAL_ZGEN_SETUP) updated; creating a new init.zsh from plugin list in ${REAL_ZGEN_SETUP}"
setup-zgen-repos
elif [ -d ~/.zshrc.add-plugins.d ]; then
init_timestamp=$(get_file_modification_time ~/.zgenom/init.zsh)
plugins_dir_timestamp=$(get_file_modification_time ~/.zshrc.add-plugins.d)
if [ "$plugins_dir_timestamp" -gt "$init_timestamp" ]; then
need_update="true"
fi
if [[ -n "$(ls -A ~/.zshrc.add-plugins.d)" ]] && [[ -z $need_update ]]; then
for file in ~/.zshrc.add-plugins.d/*; do
if [[ $(get_file_modification_time "${file}") -gt ${init_timestamp} ]]; then
need_update="true"
break
fi
done
fi
if [[ -n $need_update ]]; then
echo "Some files in ~/.zshrc.add-plugins.d updated; creating a new init.zsh from plugin list in ${REAL_ZGEN_SETUP} and plugins dir"
setup-zgen-repos
fi
unset init_timestamp
unset plugins_dir_timestamp
unset need_update
fi
unset REAL_ZGEN_SETUP