-
Notifications
You must be signed in to change notification settings - Fork 0
/
circuit-utility
292 lines (248 loc) · 7.69 KB
/
circuit-utility
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
#
# DeLorean utility circuit.
#
circuit 'mr.fusion' 'spectrum'
digest ${ZDOTDIR}/circuits/utility/{comple,func}tions/*
function circuit-utility {
# Correct commands.
setopt CORRECT
#
# Aliases
#
# Disable correction.
alias ack='nocorrect ack'
alias cd='nocorrect cd'
alias cp='nocorrect cp'
alias ebuild='nocorrect ebuild'
alias gcc='nocorrect gcc'
alias gist='nocorrect gist'
alias grep='nocorrect grep'
alias heroku='nocorrect heroku'
alias ln='nocorrect ln'
alias man='nocorrect man'
alias mkdir='nocorrect mkdir'
alias mv='nocorrect mv'
alias mysql='nocorrect mysql'
alias rm='nocorrect rm'
# Disable globbing.
alias bower='noglob bower'
alias fc='noglob fc'
alias find='noglob find'
alias ftp='noglob ftp'
alias history='noglob history'
alias locate='noglob locate'
alias rake='noglob rake'
alias rsync='noglob rsync'
alias scp='noglob scp'
alias sftp='noglob sftp'
# Define general aliases.
alias _='sudo'
alias b='${(z)BROWSER}'
alias cp="${aliases[cp]:-cp} -i"
alias e='${(z)VISUAL:-${(z)EDITOR}}'
alias ln="${aliases[ln]:-ln} -i"
alias mkdir="${aliases[mkdir]:-mkdir} -p"
alias mv="${aliases[mv]:-mv} -i"
alias p='${(z)PAGER}'
alias po='popd'
alias pu='pushd'
alias rm="${aliases[rm]:-rm} -i"
alias type='type -a'
alias t='type'
function w3md() {
multimarkdown "$1" | w3m -T 'text/html'
}
grab() {
grab="$(eval "$@")"
echo ${grab}
}
# ls
if is-callable 'dircolors'; then
# GNU Core Utilities
alias ls='ls --group-directories-first'
if zstyle -t ':delorean:circuit:utility:ls' color; then
if [[ -s "$HOME/.dir_colors" ]]; then
eval "$(dircolors --sh "$HOME/.dir_colors")"
else
eval "$(dircolors --sh)"
fi
alias ls="${aliases[ls]:-ls} --color=auto"
else
alias ls="${aliases[ls]:-ls} -F"
fi
else
# BSD Core Utilities
if zstyle -t ':delorean:circuit:utility:ls' color; then
# Define colors for BSD ls.
export LSCOLORS='exfxcxdxbxGxDxabagacad'
# Define colors for the completion system.
export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=36;01:cd=33;01:su=31;40;07:sg=36;40;07:tw=32;40;07:ow=33;40;07:'
alias ls="${aliases[ls]:-ls} -G"
else
alias ls="${aliases[ls]:-ls} -F"
fi
fi
alias l='ls -1A' # Lists in one column, hidden files.
alias ll='ls -lh' # Lists human readable sizes.
alias lr='ll -R' # Lists human readable sizes, recursively.
alias la='ll -A' # Lists human readable sizes, hidden files.
alias lm='la | "$PAGER"' # Lists human readable sizes, hidden files through pager.
alias lx='ll -XB' # Lists sorted by extension (GNU only).
alias lk='ll -Sr' # Lists sorted by size, largest last.
alias lt='ll -tr' # Lists sorted by date, most recent last.
alias lc='lt -c' # Lists sorted by date, most recent last, shows change time.
alias lu='lt -u' # Lists sorted by date, most recent last, shows access time.
alias sl='ls' # I often screw this up.
alias cl='c; l' # Clears the screen before listing in one column.
# List and grep.
function lsg() {
local keyword="$(echo "$@" | sed 's/ /.*/g')"
ls -GgthrA | grep -iE "${keyword}"
}
# Lists hidden files.
function lsd() {
ls -Ad "${@:-$PWD}/".*
}
# Lists symbolic links.
function lss() {
ls -la "${@:-$PWD}" | grep .-\>
}
# Lists numerical permissions.
function lsmod() {
ls -l "${@:-$PWD}" | awk '{k=0;for(i=0;i<=8;i++) \
k+=((substr("$1",i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
}
# Grep
if zstyle -t ':delorean:circuit:utility:grep' color; then
export GREP_COLOR='37;45' # BSD.
export GREP_COLORS="mt=$GREP_COLOR" # GNU.
alias grep="${aliases[grep]:-grep} --color=auto"
fi
# Mac OS X Everywhere
if [[ "$OSTYPE" == darwin* ]]; then
alias o='open'
elif [[ "$OSTYPE" == cygwin* ]]; then
alias o='cygstart'
alias pbcopy='tee > /dev/clipboard'
alias pbpaste='cat /dev/clipboard'
else
alias o='xdg-open'
if (( $+commands[xclip] )); then
alias pbcopy='xclip -selection clipboard -in'
alias pbpaste='xclip -selection clipboard -out'
elif (( $+commands[xsel] )); then
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
fi
fi
alias pbc='pbcopy'
alias pbp='pbpaste'
alias -g vv='$(pbp)'
alias -g rr='${grab}'
alias cpy='tr -d "\n" | pbcopy'
alias pubkey='more ~"/.ssh/id_rsa.pub" | cpy | echo "Key copied to clipboard."'
# File Download
if (( $+commands[curl] )); then
alias get='curl --continue-at - --location --progress-bar --remote-name --remote-time'
elif (( $+commands[wget] )); then
alias get='wget --continue --progress=bar --timestamping'
fi
# Resource Usage
alias df='df -kh'
alias du='du -d1 -kh'
if (( $+commands[htop] )); then
alias top=htop
else
if [[ "$OSTYPE" == (darwin*|*bsd*) ]]; then
alias topc='top -o cpu'
alias topm='top -o vsize'
else
alias topc='top -o %CPU'
alias topm='top -o %MEM'
fi
fi
# Miscellaneous
# Serves a directory via HTTP.
alias http-serve='python -m SimpleHTTPServer'
# Reloads the default shell.
alias rel='unset DELOREAN_ENV_EXISTS; exec "${SHELL}"'
# Prints the SHA1 hash of a passed file.
alias sha='openssl sha1'
# Lists open files.
alias pp='sudo lsof -i'
#
# Functions
#
# Makes a directory and changes to it.
function mkcd {
[[ -n "$1" ]] && mkdir -p "$1" && builtin cd "$1"
}
# Changes to a directory and lists its contents.
function cdls {
builtin cd "$argv[-1]" && ls "${(@)argv[1,-2]}"
}
# Pushes an entry onto the directory stack and lists its contents.
function pushdls {
builtin pushd "$argv[-1]" && ls "${(@)argv[1,-2]}"
}
# Pops an entry off the directory stack and lists its contents.
function popdls {
builtin popd "$argv[-1]" && ls "${(@)argv[1,-2]}"
}
# Prints columns 1 2 3 ... n.
function slit {
awk "{ print ${(j:,:):-\$${^@}} }"
}
# Finds files and executes a command on them.
function find-exec {
find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \;
}
# Recover vim swap files matching passed pattern into tabs.
function vim-recover {
vim -p $(find . -name "*${1}*.swp" | sed -e 's/.swp$//g;s/\/\./\//g;' | xargs echo)
}
# Displays user owned processes status.
function psu {
ps -U "${1:-$LOGNAME}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}"
}
# Search all files in the passed directory for a string.
function fs() {
find "$1" -print0 | xargs -0 grep "${@:2}"
}
# Pipe tree output into the less pager.
function treep() {
if (( $+commands[tree] )); then
tree -CN "$@" | less -r
fi
}
# Tell me what it is.
function wat() {
echo
echo 'type:'
echo '-----'
echo
type "$1"
echo
echo 'which -a:'
echo '---------'
echo
which -a "$1"
echo
echo 'command -v:'
echo '-----------'
echo
command -v "$1"
echo
}
#
# Prompt helpers.
#
# Decodes unicode glyphs into a script-safe representation.
alias glyph2hex='function { for g ($@) print -f "\\\x%s" $(printf $g | xxd -p -c1 -u) && print; }'
alias glyph2codepoint='function { for g ($@) print -n $g | iconv -f utf-8 -t UTF-32BE | xxd -p | sed -e "s/^0*/\\\U/"; }'
# Previews every possible color to see how it looks in the terminal.
alias colorlist='for code ({000..255}) print -P -- "$code: %F{$code}This is how your text would look like%f"'
# Previews plain/bold/highlight/bold+highlight in the terminal.
alias fontstyle='print -f "\e[0;31mplain\n\e[1;31mbold\n\e[0;91mhighlight\n\e[1;91mbold+highlight\n\e[0m"'
}
return 0