-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdot_zshrc.tmpl
308 lines (256 loc) · 8.59 KB
/
dot_zshrc.tmpl
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
# ~/.zshrc: This file is executed in interactive shells after /etc/zshrc.
# Put here any customization.
# bootTimeStart=$(gdate +%s%N) # In mac you'll need brew's coreutils package
local config_dir="$HOME/.config/zsh"
local plugins_dir="$config_dir/plugins"
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
# Utility function to check if a command exists.
# It is used inside these zsh config files.
#
# Example:
# has 'echo' && alias hi="echo 'hello $USER'"
function has() {
type $1 > /dev/null 2>&1
}
function zplugins_update() {
local config_dir="$HOME/.config/zsh"
local plugins_dir="$config_dir/plugins"
local current_dir=$PDW
if test -d $plugins_dir; then
for plug in $plugins_dir/*; do
echo "Updating $plug"
cd $plug
git pull
cd $current_dir
done
unset plug
fi
}
# Create a dir and go inside it.
function mkcd() {
mkdir -p "$1" && cd "$1";
}
# A very handy function from the Grml distro’s excellent zsh config
# that lets you search for running processes.
#
# Link: http://onethingwell.org/post/14669173541/any
function any() {
emulate -L zsh
unsetopt KSH_ARRAYS
if [[ -z "$1" ]] ; then
echo "any - grep for process(es) by keyword" >&2
echo "Usage: any <keyword>" >&2
return 1
else
ps xauwww | grep -i --color=auto "[${1[1]}]${1[2,-1]}"
fi
}
# Use the remote service explain.com from the terminal.
#
# Link: https://github.com/schneems/explain_shell#without-rubygems
function explain() {
# base url with first command already injected
# $ explain tar
# => http://explainshel.com/explain/tar?args=
url="http://explainshell.com/explain/$1?args="
# removes $1 (tar) from arguments ($@)
shift;
# iterates over remaining args and adds builds the rest of the url
for i in "$@"; do
url=$url"$i""+"
done
# opens url in browser
open $url
}
# Print the weather in the terminal using http://wttr.in
#
# Usage:
# weather [city]
#
# Example:
# $ weather
# # => Prints Berlin weather
# $ weather Dublin
# # => Prints Dublin weather
function weather() {
local city="$1"
[[ -z $city ]] && city="Berlin"
curl "http://wttr.in/$city"
}
# Run neovim with Codi scratchpad enabled
#
# Usage:
# codi [filetype] [filename]
#
# Example:
# $ codi javascript test.js
function codi() {
local syntax="${1:-javascript}"
shift
nvim -c \
"let g:startify_disable_at_vimenter = 1 |\
set bt=nofile ls=0 noru nonu nornu |\
hi ColorColumn ctermbg=NONE |\
hi VertSplit ctermbg=NONE |\
hi NonText ctermfg=0 |\
Codi $syntax" "$@"
}
# ZSH renaming tool
# Link: http://www.mfasold.net/blog/2008/11/moving-or-renaming-multiple-files/
#
# Example:
# % mmv '(*).json' '$1.rb'
autoload -U zmv
alias mmv='noglob zmv -W'
# ---------------------------------------------------------------------------
# Aliases
# ---------------------------------------------------------------------------
alias _='sudo'
alias cl='clear'
alias pingg='ping -c 4 www.duckduckgo.com'
alias rake='noglob rake' # makes rake work nicely with zsh
alias ..='cd ..'
alias ...='cd ../..'
alias rm='rm -i'
alias bi='bundle install'
alias bu='bundle update'
alias be='bundle exec'
# show full history
alias hs='fc -l 1'
# search command in history
# link: http://viget.com/extend/level-up-your-shell-game#history-expansions
alias 'h?'='history | grep'
# don't save current history in the global history file.
# history will be lost once the session is closed.
alias hide='fc -pa'
# find the option for using colors in ls, depending on the version: Linux or BSD
ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G'
has eza && alias ll='eza -l'
has eza || alias ll='ls -l'
has eza && alias la='eza -a'
has eza || alias la='ll -a'
# higher-order function: map
# link: https://coderwall.com/p/4tkkpq
alias map='xargs -n1'
# disk space
alias dus='du -Psckx * | sort -nr'
# Format JSON text with python
alias pyson='python -m json.tool'
# most used tools
alias g='git'
alias nv='nvim'
# mimic macOS pbcopy and pbpaste
has pbcopy || alias pbcopy='xclip -i -selection clipboard'
has pbpaste || alias pbpaste='xclip -o -selection clipboard'
# source: https://github.com/direnv/direnv/wiki/Tmux
has direnv && alias tmux='direnv exec / tmux'
# ---------------------------------------------------------------------------
# History
# ---------------------------------------------------------------------------
# ignore duplicate history entries
setopt histignoredups
# Appends every command to the history file once it is executed
setopt inc_append_history
# Reloads the history whenever you use it
setopt share_history
# keep more history
export HISTFILE=$HOME/.zsh_history
export HISTSIZE=10000
export SAVEHIST=10000
export DIRSTACKSIZE=50
# ---------------------------------------------------------------------------
# Edit command line
# ---------------------------------------------------------------------------
autoload -U edit-command-line
zle -N edit-command-line
# ---------------------------------------------------------------------------
# Bindkeys
# ---------------------------------------------------------------------------
bindkey "^R" history-incremental-search-backward
bindkey '\C-x\C-e' edit-command-line
# Autosuggestions
bindkey '^ ' autosuggest-accept
# ---------------------------------------------------------------------------
# VI Mode
# ---------------------------------------------------------------------------
bindkey -v
bindkey '^P' up-history
bindkey '^N' down-history
bindkey '^?' backward-delete-char
bindkey '^h' backward-delete-char
bindkey '^w' backward-kill-word
bindkey '^r' history-incremental-search-backward
bindkey '^a' beginning-of-line
bindkey '^e' end-of-line
# Visual mode enters the editor
bindkey -M vicmd 'v' edit-command-line
export KEYTIMEOUT=1
# ---------------------------------------------------------------------------
# Vendor
# ---------------------------------------------------------------------------
# Run ssh-agents with keychain
has keychain && eval `keychain --eval --noask --quiet id_rsa`
# Direnv
has direnv && eval "$(direnv hook zsh)"
# Use fnm as a node version manager
has fnm && eval "$(fnm env --use-on-cd)"
# Use frum as a ruby version manager
has frum && eval "$(frum init)"
# typeset -U path
# nodenv configuration
# if [[ -d "$HOME/.nodenv/shims" ]]; then
# path=("$HOME/.nodenv/shims" $path)
# fi
# rbenv configuration
# if [[ -d "$HOME/.rbenv/shims" ]]; then
# path=("$HOME/.rbenv/shims" $path)
# fi
# Exercism
if [ -f ~/.config/exercism/exercism_completion.zsh ]; then
source ~/.config/exercism/exercism_completion.zsh
fi
# ---------------------------------------------------------------------------
# Local settings
# ---------------------------------------------------------------------------
# Set this file for custom local changes
if [ -f "$config_dir/local.rc.zsh" ]; then
source "$config_dir/local.rc.zsh"
fi
# ---------------------------------------------------------------------------
# Completions
# ---------------------------------------------------------------------------
autoload -Uz compinit
compinit
zmodload -i zsh/complist
# completion styles
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' # case insensitive
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*:*:*:*:processes' command "ps -o pid,user,tty,comm -w"
zstyle ':completion:*:warnings' format '%B%U---- no match for: %d%u%b'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
# ---------------------------------------------------------------------------
# Plugins
# ---------------------------------------------------------------------------
source "$plugins_dir/zsh-autosuggestions/zsh-autosuggestions.zsh"
# ---------------------------------------------------------------------------
# Prompt
#
# Check for starship.rs or fallback to the custom prompt if not present
# ---------------------------------------------------------------------------
has starship && eval "$(starship init zsh)" || source "$config_dir/prompt.zsh"
{{ if (.codespaces) -}}
# In codespaces the GOPATH/bin dir is not set properly, this tries to fix it
# This has to be done in the zshrc because that's where codespaces' zsh config
# sets env vars
typeset -U path
if [[ -d "$GOPATH/bin" ]]; then
path=("$GOPATH/bin" $path)
fi
{{- end }}
# bootTimeDuration=$((($(gdate +%s%N) - $bootTimeStart)/1000000))
# echo $bootTimeDuration ms overall boot duration
# vim:set ft=zsh: