-
Notifications
You must be signed in to change notification settings - Fork 5
/
my_functions.zsh
372 lines (306 loc) · 7.58 KB
/
my_functions.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
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# Make `l` and others use exa command
# When showing hidden files should always hide .DS_Store
alias l="exa --header --long -a --color=always | grep -vE '\.DS_Store$' --color=always"
alias ll="exa --header --long"
alias ls="exa"
alias la="l"
# Make `ds` use docker ps --all
alias ds="docker ps --all"
# Make `dn` use docker network ls
alias dn="docker network ls"
# Make `dv` use docker volume ls
alias dv="docker volume ls"
# Make `cls` be a shortcut to running `clear`
alias cls="clear"
# Swap letters list
alias sl="ls"
alias al="l"
# Swap letters docker ps --all
alias sd="docker ps --all"
# Swap letters docker network ls
alias nd="docker network ls"
# Swap letters docker volume ls
alias vd="docker volume ls"
# Make `tree` ignore node_modules
alias tree="tree -I 'node_modules'"
# Make `mvn archetype:generate` be `mvn-init`
alias mvn-init="mvn archetype:generate"
# Vim alias
alias v="vim"
alias vi="vim"
# First mvim run should become a listen server for any file open requests
function run_mvim {
mvim --serverlist | grep -q VIM
if [ $? -eq 0 ]; then
if [ $# -eq 0 ]; then
mvim
else
mvim --remote "$@"
fi
else
mvim --servername VIM "$@"
fi
}
urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
# Write our individual settings to the gitconfig file
function dgitconfig () {
if ! [[ -z $GITHUB_USERNAME ]] && \
! [[ -z $GITHUB_FULLNAME ]] && \
! [[ -z $GITHUB_EMAIL ]] && \
! [[ -z $GITHUB_GPG_SIGN_KEY ]] && \
! [[ -z $GITHUB_GPG_SHOULD_SIGN ]] ; then
# Create a non tracked custom gitconfig
export GITHUB_CUSTOM_GITCONFIG="$HOME/.${GITHUB_USERNAME}-gitconfig"
git config \
--file="$GITHUB_CUSTOM_GITCONFIG" \
user.name $GITHUB_FULLNAME
git config \
--file="$GITHUB_CUSTOM_GITCONFIG" \
user.email $GITHUB_EMAIL
git config \
--file="$GITHUB_CUSTOM_GITCONFIG" \
user.signingkey $GITHUB_GPG_SIGN_KEY
git config \
--file="$GITHUB_CUSTOM_GITCONFIG" \
commit.gpgsign $GITHUB_GPG_SHOULD_SIGN
# Include my not tracked custom gitconfig from my tracked one
git config \
--file="$MY_DOTTIES_DIR/gitconfig" \
include.path $GITHUB_CUSTOM_GITCONFIG
fi
}
# Extract Payload from inside of a pkg
function epackage () {
pkgutil --expand "$1.pkg" "/tmp/$1"
echo "Files extracted to: /tmp/$1"
}
# Extract Payload from inside of a pkg
function epayload () {
# Two possible ways payloads could be compressed
pbzx -n Payload
if [ $? -eq 0 ]
then
pbzx -n Payload | cpio -i
else
cat Payload | gzip -d | cpio -id
fi
echo "Files extracted to current directory"
}
# Game Audio Create - Takes a wav file and creates both
# ogg and m4a leveraging ffmpeg
function gacreate () {
ffmpeg -i "$1" -c:a libfdk_aac -b:a 128k "$(echo $1 | cut -f 1 -d '.').m4a"
ffmpeg -i "$1" -c:a libvorbis -qscale:a 5 "$(echo $1 | cut -f 1 -d '.').ogg"
}
# Allows us to change node version based on project .nvmrc
function setnvm () {
if [ "$PWD" != "$MYOLDPWD" ]; then
MYOLDPWD="$PWD";
if [ -e "$PWD/.nvmrc" ]; then
nvm use
fi
fi
}
# Override cd to also run our nvm checker
function cd () {
if [ "$NVMUSE" == "1" ]; then
builtin cd "$@" && setnvm;
else
builtin cd "$@";
fi
}
# -- Begin Prompt configuration --
# Returns $1 as the current branch
function getGitBranch {
local fullRefsHead
fullRefsHead=`git symbolic-ref HEAD 2> /dev/null`
# If we were able to run the git command with success
[[ $? == 0 ]] \
&& eval "$1='${fullRefsHead//refs\/heads\//}'" \
|| eval "$1=''";
}
# Returns the git status portion of the prompt in $3
function git_info () {
local gitBranch
getGitBranch gitBranch
# Hotfix: Chromium repo is too big to check if dirty
case `pwd` in
# If the current folder we are in is part of `Chromium`
# Use our function to determine branch w/out status
(*Chromium/src*)
eval "$3='[ ${1}${gitBranch}${2} ]'" \
;;
# If current directory is initialized with git
# Let our zsh command determine branch and status
(*)
[[ -n $gitBranch ]] \
&& eval "$3='[ ${1}${gitBranch}$(parse_git_dirty)${2} ]'" \
|| eval "$3=''"
;;
esac
}
# Enable prompt substitution
setopt promptsubst
# Executed before each prompt print
function precmd () {
# Set color variables
local CB=$'%{$fg_bold[blue]%}'
local CBB=$'%{$fg_bold[blue]%}'
local CBG=$'%{$fg_bold[green]%}'
local CW=$'%{$fg[white]%}'
# Reset
local RS=$'%{$reset_color%}'
# Newline
local NL=$'\n'
# Datetime print
local DT=$'%D{[%X]} '
# Folder print
local FP=$'[%3/] '
# Git Prompt print
local GP
git_info $CBG $RS GP
# Command Prompt
local CP="${CB}->${CBB} %# ${RS}"
# Main Prompt
local MP="${CB}${DT}${RS}${GP}${NL}${CW}${FP}${NL}${CP}"
# Set Prompt
PS1="${MP}"
}
# Enable precmd functions
typeset -a precmd_functions
# Add a custom function to the list of precmd functions
#precmd_functions+=()
# -- End Prompt configuration --
function getip {
# Ping whatever site was passed as the first argument
# Strip the ip address returned from the output
# Remove newlines from the end of the response output
# Copy the returned value to the clipboard
ping -c 1 $1 | grep "64 bytes from " | awk '{print $4}' | cut -d":" -f1 | tr -d "\n" | pbcopy
}
function chkport {
# Checks what application if any is listening on a port
lsof -n -i:$1 | grep LISTEN
}
# Edit nginx Servers
function nedit {
cd /usr/local/etc/nginx/servers && \
$VIM_PATH && \
cd -
}
function nreload {
brew services restart nginx-full
}
function nstart {
brew services start nginx-full
}
function nstop {
brew services stop nginx-full
}
function nluapkg {
cd /usr/local/Cellar/luajit/2.0.4_3/share/luajit-2.0.4 && \
$VIM_PATH && \
cd -
}
function nluapkgb {
cd /usr/local/Cellar/luajit/2.0.4_3/share/luajit-2.0.4
}
function nluapkgc {
echo "/usr/local/Cellar/luajit/2.0.4_3/share/luajit-2.0.4" | pbcopy
}
function nconf {
cd /usr/local/etc/nginx && \
$VIM_PATH && \
cd -
}
function nconfb {
_l=`pwd`
cd /usr/local/etc/nginx
}
function nconfc {
echo "/usr/local/etc/nginx" | pbcopy
}
function nhome {
cd /usr/local/Cellar/nginx-full/1.12.0 && \
$VIM_PATH && \
cd -
}
function nhomeb {
_l=`pwd`
cd /usr/local/Cellar/nginx-full/1.12.0
}
function nhomec {
echo "/usr/local/Cellar/nginx-full/1.12.0" | pbcopy
}
function nlog {
cd /usr/local/var/log/nginx && \
$VIM_PATH && \
cd -
}
function nlogb {
_l=`pwd`
cd /usr/local/var/log/nginx
}
function nlogc {
echo "/usr/local/var/log/nginx" | pbcopy
}
function nwww {
cd /usr/local/var/www && \
$VIM_PATH && \
cd -
}
function nwwwb {
_l=`pwd`
cd /usr/local/var/www
}
function nwwwc {
echo "/usr/local/var/www" | pbcopy
}
# If dotties is installed then make some functions
if [[ -d $MY_DOTTIES_DIR ]] ; then
function dhelp {
echo "Commands";
echo "dssh, dclean, dreset, dcommit 'msg', dpull, dpush, dedit";
}
function dssh {
cd $MY_DOTTIES_DIR && \
git-ssh afaur/dotties && \
git branch --set-upstream-to=origin/master && \
cd -
}
function dclean {
cd $MY_DOTTIES_DIR && \
git clean -df && \
cd -
}
function dreset {
cd $MY_DOTTIES_DIR && \
git reset --hard origin/master && \
cd -
}
function dcommit {
cd $MY_DOTTIES_DIR && \
git add -A && \
git commit -m $1 && \
cd -
}
function dpull {
cd $MY_DOTTIES_DIR && \
git pull && \
cd -
}
function dpush {
cd $MY_DOTTIES_DIR && \
git push && \
cd -
}
function dedit {
cd $MY_DOTTIES_DIR && \
$VIM_PATH && \
cd -
}
function dbrowse {
_l=`pwd`
cd $MY_DOTTIES_DIR
}
fi