forked from digitalresistor/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
194 lines (157 loc) · 4.02 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
# Set our preferred EDITOR in this order
EDITOR_BY_PREF=(
/opt/homebrew/bin/nvim
/usr/local/bin/nvim
/opt/homebrew/bin/vim
/usr/local/bin/vim
/usr/bin/vim
/usr/bin/vi
/usr/bin/nano
)
for EDITOR in $EDITOR_BY_PREF; do
if [[ -x $EDITOR ]]; then
export EDITOR
break
fi
done
# Thanks, but no thanks.
export HOMEBREW_NO_ANALYTICS=1
alias edit=$EDITOR
if [[ "$EDITOR" = */nvim ]]; then
alias vim=$EDITOR
alias vi=$EDITOR
fi
HAS_VIMR=$(whence vimr)
if [[ $? -eq 0 && -x $HAS_VIMR ]]; then
alias mvim="vimr -n"
fi
# Always substitute the prompt each time we switch directories
setopt prompt_subst
# Hostname:path $/#
PROMPT='%m ${PWD/#$HOME/~} %# '
function chpwd_change_tabname {
printf "\e]1;${PWD/#$HOME/~}\a"
}
chpwd_functions=(${chpwd_functions[@]} "chpwd_change_tabname")
chpwd_change_tabname
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.zsh_history
# Eventhough I am a VIM user, I prefer emacs bindings in my shell
bindkey -e
# I want to be able to search the history with patterns
bindkey '^R' history-incremental-pattern-search-backward
function lsockets {
lsof -a -c $1 -i -l -P
}
function activate {
if [[ -d ~/.ve/$1 ]]; then
echo "Activating $1 virtual environment"
source ~/.ve/$1/bin/activate
export GEM_HOME="$VIRTUAL_ENV/gems"
export GEM_PATH=""
export PATH=$PATH:"$GEM_HOME/bin"
else
echo "That virtual environment does not exist!"
fi
}
function tabname {
printf "\e]1;$1\a"
}
function winname {
printf "\e]2;$1\a"
}
function random_string {
cat /dev/urandom | env LC_CTYPE=UTF8 tr -cd 'a-fA-F0-9' | head -c $1
}
function start_smtpd {
if [ ""$1 == "" ]; then
PORT=25
else
PORT=$1
fi
python -m smtpd -n -c DebuggingServer localhost:$PORT
}
function run_gmalloc {
# Sub shell
(
export MallocStackLogging=1
export MallocCheckHeapStart=1000
export MallocCheckHeapEach=100
export MallocScribble=1
export MallocPreScribble=1
export MallocStackLoggingNoCompact=1
$@)
}
function tox {
PYENV=$(whence pyenv)
if [[ ! -v TOX_PATH && -x $PYENV ]]; then
for pyv in $(pyenv versions --bare | sort -g -r); do
TOX_PATH="$TOX_PATH:$(pyenv prefix $pyv)/bin"
done
fi
export TOX_PATH=$TOX_PATH
env PATH="$TOX_PATH:$PATH" tox $@
}
_shutdown_sleep () {
return 0
}
function sleep_countdown {
_SLEEP_COUNT=$1
trap _shutdown_sleep SIGINT
while [[ $_SLEEP_COUNT -gt 0 ]]; do
printf "Sleeping %d more seconds." $_SLEEP_COUNT
sleep 1
if [[ $? != 0 ]]; then
trap SIGINT
return 1
else
printf "\033[2K\r"
_SLEEP_COUNT=$(( _SLEEP_COUNT - 1 ))
fi
done
trap SIGINT
}
function run_forever {
SLEEP_COUNT=$1
shift
while true; do
$@
sleep_countdown $SLEEP_COUNT
if [[ $? != 0 ]]; then
echo "To end loop, press ^C"
sleep 1
fi
done
}
function count_redir {
curl -s -L -I -D - -o /dev/null $1 | awk '
BEGIN { redir = 0; status = 200; }
tolower($1) ~ /http/ { redir=redir+1; status=$2 }
tolower($1) ~ /location:/ { print redir, status, $2 }
END {
print "Completed, with ", redir-1, "redirects. Final result: ", status
}'
}
function curlt {
curl -w "\
namelookup: %{time_namelookup}s\n\
connect: %{time_connect}s\n\
appconnect: %{time_appconnect}s\n\
pretransfer: %{time_pretransfer}s\n\
redirect: %{time_redirect}s\n\
starttransfer: %{time_starttransfer}s\n\
time_total: %{time_total}s\n\
size_header: %{size_header} bytes\n\
size_download: %{size_download} bytes\n\
speed_download: %{speed_download} bytes/sec\n\
speed_upload: %{speed_upload} bytes/sec\n\
---------------\n\
total: %{time_total}s\n" "$@"
}
function tree {
find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
}
if [ -f ~/.zsh_profile.local ]; then
. ~/.zsh_profile.local
fi