-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreal_zshrc
560 lines (469 loc) · 13.3 KB
/
real_zshrc
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
#if [ "$TMUX" ]
#then
# export TERM=xterm-256color
#fi
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
if [ -z "$ZSH_THEME" ]
then
if [[ "$SSH_CONNECTION" ]]
then
ZSH_THEME="cloud"
else
ZSH_THEME="refined"
fi
fi
if [ -z "$$XDG_CONFIG_HOME" ]
then
export XDG_CONFIG_HOME="$HOME/.config"
fi
# ========================================
# Plugin Configuration
# ========================================
export autoenv_dir=/usr/share/autoenv
# ========================================
# OS Specific Plugins
# ========================================
OS_PLUGINS=()
# How to check if running in Cygwin, Mac or Linux?
# https://stackoverflow.com/a/27776822
if [ ! -f "$HOME/.zsh-os-plugins" ]
then
case "$(uname -s)" in
Darwin)
OS_PLUGINS+=(osx)
if brew --version &> /dev/null
then
OS_PLUGINS+=(brew)
fi
;;
Linux)
OS="$(cat /etc/os-release | grep -E '^ID=' | sed 's/^.*=//g' | sed 's/\"//g')"
case "$OS" in
debian)
OS_PLUGINS+=(debian)
;;
ubuntu)
OS_PLUGINS+=(ubuntu)
;;
fedora)
OS_PLUGINS+=(fedora)
# Use dnf --version because the fedora docker container doesn't have a `which` command
if dnf --version &> /dev/null
then
OS_PLUGINS+=(dnf)
fi
;;
suse|opensuse)
OS_PLUGINS+=(suse)
;;
*)
OS_LIKE="$(cat /etc/os-release | grep -E '^ID_LIKE=' | sed 's/^.*=//g' | sed 's/\"//g')"
case "$OS_LIKE" in
arch|archlinux)
OS_PLUGINS+=(archlinux)
;;
debian)
OS_PLUGINS+=(debian)
;;
*)
;;
esac
;;
esac
if systemctl --version &> /dev/null
then
OS_PLUGINS+=(systemd)
fi
;;
CYGWIN*|MINGW32*|MSYS*)
#God help you...
;;
*)
#some fancy BSD?
;;
esac
if man --version &> /dev/null
then
OS_PLUGINS+=(man colored-man-pages)
fi
echo "OS_PLUGINS=($OS_PLUGINS)" > "$HOME/.zsh-os-plugins"
else
source "$HOME/.zsh-os-plugins"
fi
# Additional plugins to be loaded
EXTRA_PLUGINS=(autoenv)
if [[ "$TMUX" ]]
then
EXTRA_PLUGINS+=(tmux tmuxinator vi-mode)
fi
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
if [[ -z "$plugins" ]]
then
if [[ -z "$EXTRA_PLUGINS" ]]
then
EXTRA_PLUGINS=()
fi
common_plugins=(common-aliases command-not-found gitfast thefuck)
docker_plugins=(docker docker-compose)
plugins=($OS_PLUGINS $common_plugins $EXTRA_PLUGINS)
old_plugins=($plugins)
fi
source "$ZSH/oh-my-zsh.sh"
resetplugins() {
unset plugins
source $HOME/.zshrc
}
addplugin() {
for plugin in $@
do
# Sanity check - Don't `source .zshrc` if we don't have to
if [[ $plugins == *"$plugin"* ]]
then
if [ -z "$ADDED_PLUGINS" ]
then
ADDED_PLUGINS=0
fi
continue
fi
if typeset -p "${plugin}_plugins" > /dev/null 2>&1; then
plugin+="_plugins"
plugins+=${(P)plugin}
else
plugins+=$plugin
fi
ADDED_PLUGINS=1
done
if [[ "$ADDED_PLUGINS" -eq 1 ]]
then
source $HOME/.zshrc
fi
}
_addplugin() {
PATH="/usr/local/sbin:/usr/local/bin:/usr/bin"
reply=( $(find "$ZSH/plugins" -type d -maxdepth 1 -execdir bash -c 'echo {} | cut -c 3-' \; | tail -n +2) )
}
compctl -K _addplugin addplugin
removeplugin() {
for plugin in $@
do
plugins=("${(@)plugins:#$plugin}")
done
source $HOME/.zshrc
}
_removeplugin() {
reply=($plugins)
}
compctl -K _removeplugin removeplugin
zshtheme() {
if [ -z "$1" ]
then
echo "Usage: zshtheme THEME"
else
ZSH_THEME="$1" exec zsh
fi
}
_zshtheme() {
_themes=(random)
reply=( $_themes $(ls -f "$ZSH/themes" | sed 's/.zsh-theme//g' | tail -n +3) )
}
compctl -K _zshtheme zshtheme
vim-colorscheme() {
if [[ "$1" != "" ]]
then
export VIM_COLOR_SCHEME="$1"
fi
}
_vim-colorscheme() {
PATH="/usr/local/sbin:/usr/local/bin:/usr/bin"
reply=( $(find "$HOME/.vim"/ -type d -name "colors" -execdir bash -c 'ls -f {} | grep -E ".*.vim" | rev | cut -c5- | rev' \;) )
}
compctl -K _vim-colorscheme vim-colorscheme
vim-background() {
if [[ "$1" != "" ]]
then
export LC_TERM_PROFILE="$1"
else
export LC_TERM_PROFILE=light
fi
}
_vim-background() {
reply=( light dark)
}
compctl -K _vim-background vim-background
# Reloads the virtualbox kernel modules and kills any running processes
# Run this after a VirtualBox update or when VirtualBox is being stupid
vboxreload() {
for module in {'vboxdrv','vboxnetadp','vboxnetflt','vboxpci'}
do
sudo modprobe "$module"
done
sudo pkill VBoxHeadless
sudo pkill VBoxSVC
sudo pkill VBoxXPCOMIPCD
sudo pkill VBoxSVC
}
bootiso() {
qemu-system-x86_64 -enable-kvm -cpu host -vga virtio -m 8G -cdrom "$1"
}
_bootiso() { _arguments '1: : _files -g "*.(#i)iso"' }
compdef {_,}bootiso
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
export LANG=en_GB.UTF-8
export LC_CTYPE="$LANG"
export LC_COLLATE="$LANG"
export EDITOR=nvim
export VISUAL="${EDITOR}"
export BROWSER=/usr/bin/firefox
export ANDROID_HOME="$HOME/Android/Sdk"
export PATH="${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools"
export VAULT_ADDR="http://127.0.0.1:8200"
# We may not want to look for a display e.g to save on performance when
# sourcing this profile or on a server.
FIND_DISPLAY=1
if [[ -z "$DISPLAY" && "$FIND_DISPLAY" -eq 1 ]]
then
for display in {0..10}
do
export DISPLAY=:$display
CAN_OPEN_DISPLAY=$(xrandr 2>/dev/stdout | grep "Can't open display" &> /dev/null 2>&1)
if [[ "$?" -eq 1 ]]
then
# We've found a display
break
fi
if [[ "$?" -eq 0 ]]
then
unset DISPLAY
fi
done
fi
if [[ -z "$LC_TERM_PROFILE" ]]
then
export LC_TERM_PROFILE=dark
fi
if [[ -z "$VIM_COLOR_SCHEME" ]]
then
export VIM_COLOR_SCHEME=nord
fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# ssh
# export SSH_KEY_PATH="~/.ssh/dsa_id"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
for f in cls clea cleat clearr
do
alias $f="clear"
done
alias pacuar=pacaur
alias VboxManage="VBoxManage"
alias YCM-Generator="$HOME/.vim/bundle/YCM-Generator/config_gen.py"
alias vundleinstall="nvim +PluginInstall +qall"
alias vundleupdate="nvim +PluginUpdate +qall"
alias vundleclean="nvim +PluginClean +qall"
readmd() {
for f in "$@"
do
pandoc "$f" | html2text -style pretty | less
done
}
# This doesn't work for some reason!
# To Do:
# * Find out why this doesn't work
npm-upgrade() {
updates="$(npm -g outdated | sed 's/ .*//g' | grep -v Package | xargs echo)"
if [[ "$updates" != "" ]]
then
npm install -g "$updates"
fi
}
# Use it like this:
# echo "/path/to/wallpaper.jpg | awesome-wallpaper
awesome-wallpaper() {
xargs -I '{}' echo "local gears = require(\"gears\") gears.wallpaper.maximized(\"{}\", s, true)" | awesome-client
}
diff() {
colordiff "$@" 2>&/dev/null || env diff "$@"
}
alias webtorrent="webtorrent -o \"$HOME/Downloads\""
alias kitematic="gksudo kitematic"
alias powershell="powershell -NoLogo"
alias update="sudo pacman -Su && sudo pacman -Syu && pacaur -Su"
alias fuckingwindows="find . -type f -execdir dos2unix {} \;"
#alias code=/opt/visual-studio-code/bin/code
PATH="$PATH:/opt/VSCode-linux-x64/bin"
code() {
(env code $@ &> /dev/null 2>&1 &)
}
gedit() {
(env gedit $@ &> /dev/null 2>&1 &)
}
vim() {
env nvim $@
}
vi() {
env nvim $@
}
docker() {
sudo -E env docker "$@"
}
docker-compose() {
sudo -E env docker-compose "$@"
}
calc() {
echo "$@" | bc
}
#https://superuser.com/questions/957913/how-to-fix-and-recover-a-corrupt-history-file-in-zsh#957924
fix_zsh_history() {
mv .zsh_history .zsh_history_bad
strings .zsh_history_bad > .zsh_history
fc -R .zsh_history
}
dotnet() {
if [[ "$1" == "new" ]]
then
# `dotnet new` initialises a project with files in CRLF format - Let's fix that with dos2unix...
env dotnet "$@" && dos2unix ./* &> /dev/null 2>&1
else
env dotnet "$@"
fi
}
# This abomination (there really is no other word) checks for updates to custom vagrant boxes
# using the Last-Modified HTTP header and comparing that against a known folder in $HOME/.vagrant.d/boxes/MY_BOX/
vagrant box custom-update() {
if [[ "$@" != "box custom-update" ]]
then
env vagrant "$@"
return
fi
UPDATE_NEEDED=$(xargs -0 php -r << EOF
if (!file_exists('Vagrantfile')) {
exit(1);
} else {
\$box = \`cat Vagrantfile | grep -E 'config.vm.box = ".*"' | sed 's/.*"http/http/g' | rev | cut -c 2- | rev | xargs printf \`;
}
\$normalised_box = \`echo "\$box" | sed 's/\//-VAGRANTSLASH-/g' | xargs printf\`;
\$curl = curl_init(\$box);
//don't fetch the actual page, you only want headers
curl_setopt(\$curl, CURLOPT_NOBODY, true);
//stop it from outputting stuff to stdout
curl_setopt(\$curl, CURLOPT_RETURNTRANSFER, true);
// attempt to retrieve the modification date
curl_setopt(\$curl, CURLOPT_FILETIME, true);
\$result = curl_exec(\$curl);
if (\$result === false) {
die (curl_error(\$curl));
}
\$remote_timestamp = curl_getinfo(\$curl, CURLINFO_FILETIME);
if (\$remote_timestamp == -1) {
exit(1);
}
\$HOME = getenv('HOME');
if (!isset(\$HOME)) {
exit(1);
}
//\$timestamp = filemtime(\`ls -dh \$HOME/.vagrant.d/boxes/\$normalised_box/* | head -n1\`);
\$timestamp = \`ls -dh \$HOME/.vagrant.d/boxes/\$normalised_box/* | head -n1 | xargs printf\`;
if (file_exists(\$timestamp)) {
\$timestamp = filemtime(\$timestamp);
if (\$remote_timestamp > \$timestamp) {
echo "{\"UPDATE_NEEDED\": \"" . \$normalised_box . "\", \"box\": \"" . \$box . "\"}";
} else {
echo "OK";
}
}
EOF
)
if [[ "$UPDATE_NEEDED" == "{\"UPDATE_NEEDED\":"* ]]
then
normalised_box="$(echo "$UPDATE_NEEDED" | grep -oE '{\"UPDATE_NEEDED\": \".*\",' | sed 's/.*: \"//g' | rev | cut -c 3- | rev)"
box="$(echo "$UPDATE_NEEDED" | grep -oE '\"box\": \".*\"' | sed 's/\"box\":.* \"//g' | rev | cut -c 2- | rev)"
echo "An updated box for $box is available!"
printf "Do you want to update (y/n): "
while true
do
read yn
if [[ "$yn" == "Y" || $yn == "y" || "$yn" == "N" || "$yn" == "n" ]]
then
if [[ "$yn" == "N" || "$yn" == "n" ]]
then
break;
fi
env vagrant box add "$box" --name "$normalised_box" --force; break;
else
echo "Please answer y or n";
fi
done
else
echo "Box is already up to date"
fi
}
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
export PATH="$N_PREFIX/bin:$PATH" # Use node.js in $N_PREFIX instead of the system version
export GOPATH=$HOME/.go
export PATH="$PATH:$GOPATH/bin"
export PATH="$PATH:~/.local/bin"
if [[ ! -z $DISPLAY && $- =~ i ]]
then
# Capslock as ctrl
bash -c '/usr/bin/setxkbmap -option ctrl:nocaps &> /dev/null 2>&1; exit 0'
fi
export N_PREFIX="$HOME/n"; [[ :$PATH: == *":$N_PREFIX/bin:"* ]] || PATH+=":$N_PREFIX/bin" # Added by n-install (see http://git.io/n-install-repo).
export PATH="$N_PREFIX/bin:$PATH"
checkupdates() {
if env which checkupdates &> /dev/null
then
UPDATES="$(env checkupdates)"
if [[ "$UPDATES" != "" ]]
then
echo "Updates:\n$UPDATES"
fi
fi
}
if [ -d /usr/share/undistract-me ]
then
source /usr/share/undistract-me/long-running.bash &> /dev/null 2>&1 || true
notify_when_long_running_commands_finish_install &> /dev/null 2>&1 || true
fi