forked from tangledhelix/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
348 lines (276 loc) · 9.61 KB
/
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
#
# Sets Oh My Zsh options.
#
# Authors:
# Sorin Ionescu <[email protected]>
#
# Set the key mapping style to 'emacs' or 'vi'.
zstyle ':omz:module:editor' keymap 'emacs'
# Auto convert .... to ../..
zstyle ':omz:module:editor' dot-expansion 'yes'
# Set case-sensitivity for completion, history lookup, etc.
zstyle ':omz:*:*' case-sensitive 'no'
# Color output (auto set to 'no' on dumb terminals).
zstyle ':omz:*:*' color 'yes'
# Auto set the tab and window titles.
zstyle ':omz:module:terminal' auto-title 'no'
# Set the Zsh modules to load (man zshmodules).
# zstyle ':omz:load' zmodule 'attr' 'stat'
# Set the Zsh functions to load (man zshcontrib).
zstyle ':omz:load' zfunction 'zargs' 'zmv'
# Set the Oh My Zsh modules to load (browse modules).
# The order matters.
# * 'environment' should be first.
# * 'completion' must be after 'utility'.
# * 'syntax-highlighting' should be next to last, but, it must be
# before 'history-substring-search'.
# * 'prompt' should be last
zstyle ':omz:load' omodule \
'environment' \
'terminal' \
'editor' \
'history' \
'directory' \
'spectrum' \
'utility' \
'completion' \
'git' \
'osx' \
'syntax-highlighting' \
'history-substring-search' \
'prompt'
# Set the prompt theme to load.
# Setting it to 'random' loads a random theme.
# Auto set to 'off' on dumb terminals.
zstyle ':omz:module:prompt' theme 'tangledhelix'
# This will make you shout: OH MY ZSHELL!
source "$OMZ/init.zsh"
# Customize to your needs...
umask 022
# no shared history, keep history per session
setopt no_share_history
# after ssh, set the title back to local host's name
ssh() {
if [[ -x /usr/local/bin/ssh ]]; then
/usr/local/bin/ssh $@
else
/usr/bin/ssh $@
fi
set-tab-title $(uname -n)
}
alias vi='vim'
alias view='vim -R'
alias vimdiff='vimdiff -O'
alias c='clear'
alias ppv='puppet parser validate'
cdpm() {
[[ -n "$1" ]] || { echo 'Missing argument'; return }
cd /etc/puppet/modules/$1/manifests
}
erbck() {
[[ -n "$1" ]] || { echo 'Missing argument'; return }
erb -P -x -T '-' $1 | ruby -c
}
# print the directory structure from the current directory in tree format
alias dirf="find . -type d|sed -e 's/[^-][^\/]*\// |/g' -e 's/|\([^ ]\)/|-\1/'"
# Show me time in GMT / UTC
alias utc='TZ=UTC date'
alias gmt='TZ=GMT date'
# Time in Tokyo
alias jst='TZ=Asia/Tokyo date'
# show me platform info
alias os='uname -srm'
hw() {
[[ "$(uname -s)" != 'SunOS' ]] && { echo 'This is not Solaris...'; return }
/usr/platform/$(uname -m)/sbin/prtdiag | /usr/bin/head -1 | \
sed 's/^System Configuration: *Sun Microsystems *//' | \
sed 's/^$(uname -m) *//'
}
# translate AS/RR numbers
astr() { echo "$1" | tr '[A-J0-9]' '[0-9A-J]' }
# show me installed version of a perl module
alias pmver="perl -le '\$m = shift; eval qq(require \$m) \
or die qq(module \"\$m\" is not installed\\n); \
print \$m->VERSION'"
# tell me if a perl module has a method
pmhas() {
local __module="$1"
local __method="$2"
[[ -n "__method" ]] || { echo 'Usage: pmhas <module> <method>'; return; }
local __result=$(perl -M$__module -e "print ${__module}->can('$__method');")
[[ $__result =~ 'CODE' ]] && echo "$__module has $__method"
}
# sleep this long, then beep
beep() {
local __timer=0
[[ -n "$1" ]] && __timer=$1
until [[ $__timer = 0 ]]; do
printf " T minus $__timer \r"
__timer=$((__timer - 1))
sleep 1
done
echo '- BEEP! - \a\r'
}
# fabricate a puppet module directory set
mkpuppetmodule() {
[[ -d "$1" ]] && { echo "'$1' already exists"; return }
mkdir -p $1/{files,templates,manifests}
cd $1/manifests
printf "\nclass $1 {\n\n}\n\n" > init.pp
}
# make a project directory
mkproj() {
local _usage='Usage: mkproj <desc> [<ticket>]'
[[ -z "$1" || "$1" =~ '^(-h|--help)' ]] && { echo $_usage; return }
local _dir
local _date=$(date +'%Y%m%d')
local _name="$1"
local _suffix
[[ -n "$2" ]] && _suffix="-${2}"
_dir="${_date}-${_name}${_suffix}"
[[ -d ~/$_dir ]] && { echo 'already exists!'; return }
mkdir ~/$_dir && cd ~/$_dir
}
# find a project directory
proj() {
local _usage='Usage: proj [<pattern>]'
[[ "$1" =~ '^(-h|--help)' ]] && { echo $_usage; return }
# If there's no pattern, go to the most recent project.
[[ -z "$1" ]] && { cd ~/(19|20)[0-9][0-9][01][0-9][0-3][0-9]-*(/om[1]); return }
local _this
local _choice=0
local _index=1
local _projects
typeset -a _projects
_projects=()
for _this in ~/(19|20)[0-9][0-9][01][0-9][0-3][0-9]-*$1*; do
[[ -d $_this ]] && _projects+=$_this
done 2>/dev/null
[[ $#_projects -eq 0 ]] && { echo 'No match.'; return }
[[ $#_projects -eq 1 ]] && { cd $_projects[1]; return }
for _this in $_projects[1,-2]; do
echo " [$_index] $(basename $_this)"
_index=$(( $_index + 1 ))
done
echo "* [$_index] \e[0;31;47m$(basename $_projects[-1])\e[0m"
echo
until [[ $_choice -ge 1 && $_choice -le $#_projects ]]; do
printf 'select> '
read _choice
[[ -z "$_choice" ]] && { cd $_projects[-1]; return }
done
cd $_projects[$_choice]
}
# count something fed in on stdin
alias count='sort | uniq -c | sort -n'
# Strip comment / blank lines from an output
alias stripcomments="egrep -v '^([\ \t]*#|$)'"
alias ack='ack --smart-case'
# Give me a list of the RPM package groups
alias rpmgroups='cat /usr/share/doc/rpm-*/GROUPS'
# Puppet logs
alias greppa='grep puppet-agent /var/log/daemon/debug'
alias greppm='grep puppet-master /var/log/daemon/debug'
alias tailpa='tail -F /var/log/daemon/debug | grep puppet-agent'
alias tailpm='tail -F /var/log/daemon/debug | grep puppet-master'
# Get my current public IP
alias get-ip='curl --silent http://icanhazip.com'
# less with no-wrap (oh-my-zsh default, could be useful sometimes)
alias less-nowrap='less -S'
# set tab titles
alias tt='set-tab-title'
# magic mv
# mmv *.c.orig orig/*.c
alias mmv='noglob zmv -W'
# globbing cheat sheet
globcheat() {
echo
echo '**/ recurse ***/ follow symlinks class: [...] neg: [^...] or [!...]'
echo
echo '/ dir . file * exec @ symlink = socket p pipe % device %b block %c char'
echo
echo 'r u:read w u:write x u:exec U owner-is-my-uid u123 owner is uid 123'
echo 'A g:read I g:write E g:exec G group-is-my-gid u:dan: owner is dan'
echo 'R o:read W o:write X o:exec or g123, g:dan:'
echo
echo 'm mtime default period is days + or - a value mw-1 in past week'
echo 'a atime M month w week h hour m minute s second aM-1 in past month'
echo
echo 'L file size (bytes) k kbytes m mbytes p blocks Lm+1 = larger than 1mb'
echo
echo '*(u0WLk+10m0) owner root, world write, > 10KB, mtime in past hour'
}
alias -g L='| less'
svndiff() {
if [[ -x $(which colordiff) ]]; then
svn diff "${@}" | colordiff
else
svn diff "${@}"
fi
}
if [[ $UID -eq 0 ]]; then
### Things to do only if I am root
# Messes with rdist
unset SSH_AUTH_SOCK
else
### Things to do only if I am not root
set-tab-title $(uname -n)
[[ -f ~/.rbenv/bin/rbenv ]] && eval "$(rbenv init -)"
# Check for broken services on SMF-based systems
[[ -x /bin/svcs ]] && svcs -xv
mkdir -p ~/.vim/tmp/{backup,swap,undo}
if [[ -n "$(command -v tmux)" ]]; then
alias tmux='tmux -u'
tmux_ls() {
echo "\n-- tmux sessions --\n$(tmux ls 2>/dev/null)"
}
# List tmux sessions
if [[ -z "$TMUX" && -n "$(tmux ls 2>/dev/null)" ]]; then
tmux_ls
fi
# tmux magic alias to list, show, or attach
t() {
[[ -z "$1" ]] && { tmux_ls; return }
export STY="[$1] $(uname -n)"
set-tab-title $STY
tmux -u new -s "$1" || tmux -u att -t "$1"
set-tab-title $(uname -n)
}
# Fix ssh socket for tmux happiness
if [[ -z "$TMUX" && -n "$SSH_TTY" ]]; then
if [[ -n "$SSH_AUTH_SOCK" && "$SSH_AUTH_SOCK" != "$HOME/.wrap_auth_sock" ]]; then
ln -sf "$SSH_AUTH_SOCK" "$HOME/.wrap_auth_sock"
export SSH_AUTH_SOCK="$HOME/.wrap_auth_sock"
fi
fi
fi
fi
# Mac-specific things
if [[ "$(uname -s)" = "Darwin" ]]; then
#battery_charge_meter() { $HOME/.scripts/laptop_battery_charge }
#export RPROMPT='$(battery_charge_meter)'
alias ql='qlmanage -p "$@" >& /dev/null'
alias telnet='/usr/bin/telnet -K'
alias ldd='otool -L'
# This shows which processes are using the network right now.
alias netusers='lsof -P -i -n | cut -f 1 -d " " | uniq'
# Amazon EC2 API (tools via homebrew)
#export JAVA_HOME="$(/usr/libexec/java_home)"
#export EC2_PRIVATE_KEY="$(/bin/ls $HOME/.ec2/pk-*.pem | /usr/bin/head -1)"
#export EC2_CERT="$(/bin/ls $HOME/.ec2/cert-*.pem | /usr/bin/head -1)"
#export EC2_HOME='/usr/local/Library/LinkedKegs/ec2-api-tools/jars'
#export EC2_AMITOOL_HOME='/usr/local/Library/LinkedKegs/ec2-ami-tools/jars'
# homebrew
local _pgdir='/usr/local/var/postgres'
alias postgres-start="pg_ctl -D $_pgdir -l $_pgdir/server.log start"
alias postgres-stop="pg_ctl -D $_pgdir stop -s -m fast"
# mysql from homebrew
alias mysql-start='mysql.server start'
alias mysql-stop='mysql.server stop'
# to use rmate
#alias rmate-tunnel='ssh -R 52698:localhost:52698'
fi
# local settings override global ones
[[ -s $HOME/.zshrc.local ]] && source $HOME/.zshrc.local
# Make the prompt happy so I don't have $? true on every load
__zsh_load_complete=1