forked from zoppo/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.zsh
299 lines (245 loc) · 6.83 KB
/
init.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
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
if zdefault -t ':zoppo:plugin:utility' auto-correct 'yes'; then
options:enable 'correct'
if ! terminal:is-dumb; then
# so we get nice colors with auto-correction
SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
fi
fi
# ZSH utilities {{{
if zdefault -t ':zoppo:plugin:utility:zsh' enable 'yes'; then
functions:autoload ztodo
functions:autoload zed
functions:autoload zcalc
functions:autoload zmv
alias zcp='zmv -C'
alias zln='zmv -L'
functions:autoload zargs
fi
# }}}
# GNU utilities {{{
if zdefault -t ':zoppo:plugin:utility:gnu' enable 'no'; then
function {
local prefix
local -a binaries
local cmd
zdefault -s ':zoppo:plugin:utility:gnu' prefix prefix 'g'
zdefault -a ':zoppo:plugin:utility:gnu' binaries binaries \
'base64' 'basename' 'cat' 'chcon' 'chgrp' 'chmod' 'chown' \
'chroot' 'cksum' 'comm' 'cp' 'csplit' 'cut' 'date' 'dd' 'df' \
'dir' 'dircolors' 'dirname' 'du' 'echo' 'env' 'expand' 'expr' \
'factor' 'false' 'fmt' 'fold' 'groups' 'head' 'hostid' 'id' \
'install' 'join' 'kill' 'link' 'ln' 'logname' 'ls' 'md5sum' \
'mkdir' 'mkfifo' 'mknod' 'mktemp' 'mv' 'nice' 'nl' 'nohup' 'nproc' \
'od' 'paste' 'pathchk' 'pinee' 'pr' 'printenv' 'printf' 'ptx' \
'pwd' 'readlink' 'realpath' 'rm' 'rmdir' 'runcon' 'seq' 'sha1sum' \
'sha224sum' 'sha256sum' 'sha384sum' 'sha512sum' 'shred' 'shuf' \
'sleep' 'sort' 'split' 'stat' 'stty' 'sum' 'sync' 'tac' 'tail' \
'tee' 'test' 'timeout' 'touch' 'tr' 'true' 'truncate' 'tsort' \
'tty' 'uname' 'unexpand' 'uniq' 'unlink' 'uptime' 'users' 'vdir' \
'wc' 'who' 'whoami' 'yes' \
\
'addr2line' 'ar' 'c++filt' 'elfedit' 'nm' 'objcopy' 'objdump' \
'ranlib' 'readelf' 'size' 'strings' 'strip' \
\
'find' 'locate' 'oldfind' 'updatedb' 'xargs' \
\
'libtool' 'libtoolize' \
\
'getopt' 'grep' 'indent' 'sed' 'tar' 'time' 'units' 'which'
for cmd in "$binaries[@]"; do
if ! is-command "$prefix$cmd" || is-function "$cmd"; then
continue
fi
eval "function $cmd {
$prefix$cmd \"\$@\"
}"
done
}
fi
# }}}
# ls {{{
if zstyle -t ':zoppo:plugin:utility:ls' color; then
if ! zstyle -T ':zoppo:plugin:utility:ls' colors; then
zstyle -s ':zoppo:plugin:utility:ls' colors LS_COLORS
export LS_COLORS
elif is-callable 'dircolors'; then
if [[ -s "$HOME/.dircolors" ]]; then
eval "$(dircolors "$HOME/.dircolors")"
else
eval "$(dircolors)"
fi
fi
if utility:is-gnu; then
alias+ ls '--color=auto'
else
alias+ ls '-G'
fi
else
alias+ ls '-F'
fi
# }}}
# grep {{{
if zstyle -t ':zoppo:plugin:utility:grep' color; then
function grep {
command grep --color=auto $@
}
zstyle -s ':zoppo:plugin:utility:grep' highlight-color GREP_COLOR
zstyle -s ':zoppo:plugin:utility:grep' colors GREP_COLORS
export GREP_COLOR GREP_COLORS
fi
# }}}
# whatis {{{
if (( $+commands[whatis] )) && zdefault -t ':zoppo' easter-egg 'true'; then
function whatis() {
local arg
for arg ("$argv[@]"); do
case "$arg" in
[Ll][Oo][Vv][Ee])
echo "$arg: Baby don't hurt me, don't hurt me, no more"
;;
*)
command whatis "$arg"
;;
esac
done
}
fi
# }}}
# math {{{
if zdefault -t ':zoppo:plugin:utility:math' enable 'yes'; then
zmodload zsh/mathfunc
function math {
echo $((${=@}))
}
alias m="noglob math"
fi
# }}}
# Disable Correction {{{
function {
local programs
local program
zdefault -a ':zoppo:plugin:utility' no-correct programs \
'ack' 'cd' 'cp' 'ebuild' 'gcc' 'gist' 'grep' 'heroku' 'ln' 'man' 'mkdir' 'mv' 'mysql' 'rm'
for program ("$programs[@]")
alias "$program"="nocorrect $program"
}
# }}}
# Disable Globbing {{{
function {
local programs
local program
zdefault -a ':zoppo:plugin:utility' no-glob programs \
'fc' 'find' 'ftp' 'history' 'locate' 'rake' 'rsync' 'scp' 'sftp'
for program ("$programs[@]")
alias "$program"="noglob $program"
}
# }}}
# Ignore From History {{{
function {
local programs
local program
zdefault -a ':zoppo:plugin:utility' no-history programs \
'poweroff' 'halt' 'reboot'
for program ("$programs[@]")
alias "$program"=" $program"
}
# }}}
# Enable Interactive {{{
function {
local programs
local program
zdefault -a ':zoppo:plugin:utility' interactive programs \
'cp' 'ln' 'mv' 'rm'
for program ("$programs[@]")
alias+ "$program" '-i'
}
# }}}
# Wrap In Readline {{{
is-callable rlwrap && function {
local programs
local program
zdefault -a ':zoppo:plugin:utility' readline programs \
'nc' 'telnet' 'sbcl' 'tclsh' 'mzscheme' 'iex' 'mix'
for program ("$programs[@]")
alias "$program"="rlwrap --always-readline -H '$(path:cache)/$program.history' -c -D 2 -r $program"
}
# }}}
# Directory Stuff {{{
alias+ mkdir '-p'
alias md='mkdir'
function mcd {
[[ -n "$1" ]] && mkdir -p "$1" && builtin cd "$1"
}
alias mkdcd='mcd'
function cdls {
builtin cd "$argv[-1]" && ls "${(@)argv[1,-2]}"
}
# }}}
# Mac OS X Everywhere {{{
if [[ "$OSTYPE" == darwin* ]]; then
alias o='open'
alias get='curl --continue-at - --location --progress-bar --remote-name --remote-time'
else
alias o='xdg-open'
alias get='wget --continue --progress=bar --timestamping'
if is-callable xclip; then
alias pbcopy='xclip -selection clipboard -in'
alias pbpaste='xclip -selection clipboard -out'
elif is-callable xsel; then
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
fi
fi
alias pbc='pbcopy'
alias pbp='pbpaste'
alias copy='pbc'
alias paste='pbp'
# }}}
# Fork {{{
zdefault ':zoppo:plugin:utility:fork' programs \
'firefox' 'thunderbird' 'eog' 'ristretto' 'thunar' 'evince' 'vlc' 'urxvt'
if zdefault -t ':zoppo:plugin:utility:fork' enable 'yes'; then
zstyle -a ':zoppo:plugin:utility:fork' programs programs
for cmd ("$programs[@]"); do
eval "function $cmd {
fork command $cmd \"\$@\"
}"
done
fi
# }}}
# Documentation Lookup and Man Pages {{{
function eg() {
(( $+1 )) || {
cat 1>&2 <<END
Usage: $0 [<args>...] [<expr>]
args: Arguments to pass to man.
expr: Command line argument to search for.
Defaults to jump to the "EXAMPLE" section.
Examples:
$0 find
$0 less -s
$0 1 less -s
$0 zshall HIST_IGNORE_SPACE
$0 zshall fc
END
return 1
}
local expr='^EXAMPLE'
local -a args
args=("$@")
(( $+2 )) && {
expr="^[[:blank:]]*${@[-1]}"
args=("${@[1,-2]}")
}
PAGER="less -g -s '+/$expr'" man "${=args}"
}
# }}}
# Change directory when quitting ranger {{{
ranger() {
local tempfile=$(mktemp)
trap "[[ -e \"$tempfile\" ]] && rm -f -- \"$tempfile\"" EXIT
command ranger --choosedir="$tempfile" "${@:-$PWD}"
[[ -r "$tempfile" && $(<"$tempfile") != "$PWD" ]] && cd -- "$(<"$tempfile")"
}
# }}}
# vim: ft=zsh sts=2 ts=2 sw=2 et fdm=marker fmr={{{,}}}