forked from tangledhelix/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
263 lines (208 loc) · 6.35 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
#
# Sets Oh My Zsh options.
#
# Authors:
# Sorin Ionescu <[email protected]>
#
# Set the key mapping style to 'emacs' or 'vi'.
zstyle ':omz:module:editor' keymap 'vi'
# Auto convert .... to ../..
zstyle ':omz:module:editor' dot-expansion 'no'
# 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' \
'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
perlmodver() {
local __module="$1"
[[ -n "$__module" ]] || { echo 'missing argument'; return; }
perl -M$__module -e "print \$$__module::VERSION,\"\\n\";"
}
# 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'
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\x1b[1;37m-- tmux sessions --\n$(tmux ls 2>/dev/null)\x1b[0m"
}
# 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="tmux:$1"
set-tab-title $STY
tmux -u new -s "$1" || tmux -u att -t "$1"
set-tab-title $(uname -n)
}
fi
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