-
Notifications
You must be signed in to change notification settings - Fork 9
/
.aliases
415 lines (346 loc) Β· 8.77 KB
/
.aliases
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#!/usr/bin/env bash
# # use `hub` as git wrapper
# # http://defunkt.github.com/hub/
# hub_path=$(which hub)
# if (($ + commands[hub])); then
# alias git=$hub_path
# fi
alias g="git"
# one letter aliases w/o options
alias ga="git add"
alias gb="git branch"
alias gf="git fetch"
alias gg="git grep"
alias gl="git log"
alias gm="git merge"
alias gr="git remote"
alias gs="git status"
alias gw="git whatchanged"
# merge
alias gmc="git merge --continue"
alias gma="git merge --abort"
# pull
alias gpl="git pull"
# adding
alias gaa="git add ."
alias gap="git add --patch"
alias gau="git add --update"
# branches
alias gbe="git branch --edit-description"
alias gbd="git branch -d"
alias gbdd="git branch -D"
alias gch="git checkout"
alias gcb="git checkout -b"
alias gbm="git branch --merged"
alias gbnm="git branch --no-merged"
# cherry-pick
alias gchp="git cherry-pick"
# clone
alias gcl="git clone"
# commit
alias gc="git commit -am"
alias gcm="git commit --amend --message"
# diff
alias gdt="git difftool"
alias gd="git diff --color"
alias gitfix="git diff --name-only | uniq | xargs code"
# grep
alias ggl="git grep --line-number"
alias ggg="git grep --break --heading --line-number"
# log
alias glg="git log --graph"
alias glo="git log --oneline"
# changelog
alias changelog="git log --pretty=format:"%h %ad%x09%an%x09%s" --date=short"
# push
alias gp="git push"
alias gpu="git push -u origin"
alias undopush="git push -f origin HEAD^:master"
# rebase
alias gre="git rebase"
# remote
alias gra="git remote add origin"
# stash
alias gst="git stash"
alias gsa="git stash apply"
alias gsp="git stash pop"
alias gsd="git stash drop"
# view issues
alias gbi="git browse -- issues"
# pull-request
alias gpr="git pull-request"
# better ls
alias ls="echo; colorls -A --group-directories-first"
###
# coreutils
###
# files output
alias tail="gtail -F" # follows log rotations
alias split="gsplit"
alias csplit="gcsplit"
# summarizing files
alias sum="gsum"
alias cksum="cksum"
alias md5sum="gmd5sum"
alias sha1sum="gsha1sum"
# operating on fields
alias cut="gcut"
alias paste="gpaste"
alias join="gjoin"
# basic ops
alias cp="gcp -v"
alias mv="gmv -v"
alias rm="grm -v"
alias shred="gshred"
# special filetypes
alias link="glink"
alias unlink="gunlink"
alias mkdir="gmkdir -v"
alias rmdir="grmdir -v"
alias readlink="greadlink"
# changing file attributes
alias chmod="gchmod -v"
alias chown="gchown -v"
alias chgrp="gchgrp -v"
alias touch="gtouch"
# disk usage
alias df="gdf"
alias du="gdu"
alias stat="gstat"
alias sync="gsync"
alias truncate="gtruncate"
# printing text
alias echo="gecho"
alias printf="gprintf"
# redirection
alias tee="gtee"
# the rest
alias awk="gawk"
alias grep="ggrep --color"
alias ln="gln"
alias ln-sym="gln -nsf" # symlinks
# findutils
alias find="gfind"
alias locate="glocate"
alias updatedb="gupdatedb"
alias xargs="gxargs"
# binutils
alias addr2line="gaddr2line"
alias ar="gar"
alias c++filt="gc++filt"
alias dlltool="gdlltool"
alias nlmconv="gnlmconv"
alias nm="gnm"
alias objcopy="gobjcopy"
alias objdump="gobjdump"
alias ranlib="granlib"
alias readelf="greadelf"
alias size="gsize"
alias strings="gstrings" # lol
alias strip="gstrip"
# tar
alias tar="gtar"
# sed
alias sed="gsed"
# which
alias which="gwhich"
# npm
alias nin="npm init"
alias ni="npm i"
alias nig="npm i -g"
alias nis="npm i --save"
alias nid="npm i --save-dev"
alias nu="npm uninstall"
alias nus="npm uninstall --save"
alias nud="npm uninstall --save-dev"
alias nup="npm update"
alias nug="npm upgrade"
alias nr="npm run"
alias nt="npm test"
alias ndd="npm dedupe"
alias npr="npm prune"
alias nod="npm outdated"
alias nrb="npm rebuild"
alias nls="npm list"
alias nlsg="npm list -g"
alias ncc="npm cache clean"
alias nf="npm cache clean && rm -rf node_modules && npm i"
# yarn
alias y="yarn"
alias yi="yarn init"
alias ya="yarn add"
alias yad="yarn add --dev"
alias yga="yarn global add"
alias yr="yarn run"
alias ys="yarn start"
alias yis="yarn install && yarn start"
alias yrm="yarn remove"
alias yup="yarn upgrade"
alias ycl="yarn clean"
alias ych="yarn check"
alias yt="yarn test"
alias ycc="yarn cache clean"
# pnpm
alias pn="pnpm"
alias pna="pnpm add"
alias pnr="pnpm run"
alias pni="pnpm install"
# shortcuts
alias md="mkdir"
alias t="touch"
alias x="exit"
alias c="clear"
alias o="open ."
alias vi="nvim"
alias vim="nvim"
alias v="nvim"
alias x+="chmod +x"
alias restart="sudo reboot"
alias bye="sudo shutdown -r now"
alias get="curl -O -L"
alias vi="vim"
alias reload="source ~/.zshrc"
# use ccat
alias cat="ccat"
# commonly used dirs
alias dev="cd ~/dev"
alias work="cd ~/dev/work"
alias desk="cd ~/desktop"
alias docs="cd ~/documents"
alias dl="cd ~/downloads"
alias home="cd ~"
alias dots="cd ~/dotfiles"
alias dotfiles="cd ~/dotfiles"
# python
alias pip="pip3"
# make a pdf
alias mergepdf="/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py"
# spotlight
alias spotoff="sudo mdutil -a -i off"
alias spoton="sudo mdutil -a -i on"
# remove DS_Store
alias rm_ds="find . -name '*.DS_Store' -type f -ls -delete"
# show/hide files
alias show="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
alias hide="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder"
# show/hide desktop items
alias hidedesktop="defaults write com.apple.finder CreateDesktop -bool false && killall Finder"
alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder"
# kill all chrome tabs to free memory
alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill"
# lock scren when going afk
alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
# π
alias stfu="osascript -e 'set volume output muted true'"
# remove cached xcode build data
alias xcodepurge="rm -rf ~/Library/Developer/Xcode/DerivedData"
# use gitignore.io cmd line tool
gi() {
curl -L -s https://www.gitignore.io/api/$@
}
# create a remote repo
create-repo() {
# Get user input
echo "Enter name for new repo"
read REPONAME
echo "Do you want to make it private? (y/n)"
read -r -n PRIVATE_ANSWER
if [[ "$PRIVATE_ANSWER" =~ ^[Yy]$ ]]; then
PRIVATE_TF=true
else
PRIVATE_TF=false
fi
# Curl some json to the github API oh damn we so fancy
curl -u gretzky https://api.github.com/user/repos -d "{\"name\": \"$REPONAME\", \"private\": $PRIVATE_TF}" >/dev/null
# first commit
git init 1>/dev/null
gi macos,visualstudiocode >>.gitignore 1>/dev/null
print_success ".gitignore added"
git add . 1>/dev/null
git commit -m "initial commit" 1>/dev/null
print_success "initial commit"
git remote add origin https://github.com/gretzky/$REPONAME.git 1>/dev/null
git push -u origin master --force 1>/dev/null
sleep 0.5
print_success "\nRepo created"
print_in_cyan "You can view your new repo at https://github.com/gretzky/$REPONAME.git"
}
# make new dir and cd into it
take() {
mkdir -p $1
cd $1
}
alias tk="take"
# change dir
up() {
local cdir="$(pwd)"
if [[ "${1}" == "" ]]; then
cdir="$(dirname) "${cdir}")"
elif ! [[ "${1}" =~ ^[0-9]+$ ]]; then
echo "π Arg must be a number"
elif ! [[ "${1}" -gt "0" ]]; then
echo "a POSITIVE number"
else
for i in {1..${1}}; do
local ncdir="$(dirname "${cdir}")"
if [[ "${cdir}" == "${ncdir}" ]]; then
break
else
cdir="${ncdir}"
fi
done
fi
cd "${cdir}"
}
# animated gifs from any video
# https://gist.github.com/SlexAxton/4989674
gifify() {
if [[ -n "$1" ]]; then
if [[ $2 == '--good' ]]; then
ffmpeg -i "$1" -r 10 -vcodec png out-static-%05d.png
time convert -verbose +dither -layers Optimize -resize 900x900\> out-static*.png GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - >"$1.gif"
rm out-static*.png
else
ffmpeg -i "$1" -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 >"$1.gif"
fi
else
echo "β proper usage: gifify <input_movie.mov>. You DO need to include extension."
fi
}
# defaulting tree
# tree() {
# tree -aC -I '.git|node_modules|build|dist' --dirsfirst "$@"
# }
# π
emptytrash() {
print_header "π Emptying trashes..."
sudo rm -rfv /Volumes/*/.Trashes 1>/dev/null
rm -rfv ~/.Trash/* 1>/dev/null
sudo rm -v /private/var/vm/sleepimage 1>/dev/null
}
pyenv() {
local command
command="${1:-}"
if [ "$#" -gt 0 ]; then
shift
fi
case "$command" in
rehash|shell)
eval "$(pyenv "sh-$command" "$@")"
;;
*)
command pyenv "$command" "$@"
;;
esac
}
# rename a remote git branch and update it
rename-branch() {
current_name=$1
new_name=$2
# rename the branch
git branch -m $current_name $new_name
# delete the old branch from remote and push the new name
git push origin :$current_name $new_name
# reset the upstream branch for the new_name local branch
git push origin -u $new_name
}