-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.aliases
542 lines (442 loc) Β· 12.3 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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
#!/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 cd
# alias cd="z"
# 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"
# 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 n="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 bat
alias cat="bat"
# 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"
# better pip
alias pip="uv pip"
# 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 -r 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 proteusiq 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/proteusiq/$REPONAME.git 1>/dev/null
git push -u origin main --force 1>/dev/null
sleep 0.5
print_success "\nRepo created"
print_in_cyan "You can view your new repo at https://github.com/proteusiq/$REPONAME.git"
}
# make new dir and cd into it
take() {
mkdir -p $1
cd $1 || exit
}
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}" || exit
}
# 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
}
# 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
}
# - clone and cd
git() {
if [ $1 = "clone" ]; then
command git $@ && cd "$(basename "$_" .git)"
else
command git $@
fi
}
function yy() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")"
yazi "$@" --cwd-file="$tmp"
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
cd -- "$cwd" || exit
fi
rm -f -- "$tmp"
}
# aliases
alias top="bpytop"
alias du="ncdu"
alias ls="eza --icons=always"
alias tree="eza --tree"
# uv
alias pip='uv pip'
# activate venv or .venv projects similar to deactivate
activate_venv() {
local dir=$PWD
local found=0
while [[ "$dir" != "/" && $found -eq 0 ]]; do
if [[ -f "$dir/venv/bin/activate" ]]; then
source "$dir/venv/bin/activate"
found=1
break
elif [[ -f "$dir/.venv/bin/activate" ]]; then
source "$dir/.venv/bin/activate"
found=1
break
else
dir=$(dirname "$dir")
fi
done
if [[ $found -eq 0 ]]; then
echo "No Python virtual environment found."
fi
}
alias activate=activate_venv
setenv() {
local env_file=".env"
local use_op=false
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--key) use_op=true ;;
*)
echo "β Unknown parameter: $1"
return 1
;;
esac
shift
done
# Check if .env exists
if [[ ! -f "$env_file" ]]; then
echo "β $env_file not found"
return 1
fi
process_env_line() {
local line=$1
local var_name="${line%%=*}"
local var_value="${line#*=}"
# Handle 1Password URIs
if $use_op && [[ $var_value =~ op://.*$ ]]; then
# Clean URI and fetch value
var_value="${var_value//[\"\']/}"
var_value="$(op read "$var_value")"
fi
export "$var_name=$var_value"
}
# Process each line in .env
while IFS= read -r line || [[ -n "$line" ]]; do
# Skip comments and empty lines
[[ "$line" =~ ^[[:space:]]*# || -z "$line" ]] && continue
process_env_line "$line"
done < <(grep -v '^[[:space:]]*$' "$env_file")
echo "β
Environment variables loaded from $env_file"
}
unsetenv() {
local env_file=".env"
# Check if .env exists
if [[ ! -f "$env_file" ]]; then
echo "β $env_file not found"
return 1
fi
# Process each line in .env
while IFS= read -r line || [[ -n "$line" ]]; do
# Skip comments and empty lines
[[ "$line" =~ ^[[:space:]]*# || -z "$line" ]] && continue
# Extract variable name before the = sign
local var_name="${line%%=*}"
# Unset the variable
unset "$var_name"
done < <(grep -v '^[[:space:]]*$' "$env_file")
echo "β
Environment variables unset from $env_file"
}
# remove all __pycache__ directories under a specified path
clean_pycache() {
local target_dir=$1
# Confirm target directory
if [ -z "$target_dir" ]; then
echo "Usage: clean_pycache <directory>"
return 1
fi
# Find and remove __pycache__ directories
echo "Searching for __pycache__ directories under $target_dir..."
find $target_dir -type d -name '__pycache__' -exec rm -rf {} +
}
alias clean=clean_pycache
# Productive Laziness
# llm --system 'Reply with linux terminal commands only, no extra information' --save cmd
alias cmd='llm_func() { command llm -t cmd "$@" | xargs -I {} sh -c "echo \"execute:\n\t {}\n\"; eval {}"; }; llm_func'
# tmux
alias iexit='tmux kill-session -t $(tmux display-message -p '#S')' # session exit
alias ix=iexit
alias ikill='tmux kill-server' # tmux server exit: kill all sessions
alias ik=ikill
alias iswitch='tmux choose-session' # show sessions
alias ipop='tmux display-popup -E "cd $(tmux display -p -F "#{pane_current_path}") && tmux new-session -A -s scratch"'
alias f=fuck
alias update='zsh -c ~/dotfiles/install.sh'
alias clip='pbcopy'
alias paste='pbpaste'