-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.aliases
79 lines (63 loc) · 3.06 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
# Easier navigation
alias ..="cd .."
alias ...="cd ../.."
# Enable aliases to be sudo’ed
alias sudo='sudo '
# Neovim
alias vi='nvim'
alias vim='nvim'
# Empty the Trash on all mounted volumes and the main HDD.
# Also, clear Apple’s System Logs to improve shell startup speed.
# Finally, clear download history from quarantine. https://mths.be/bum
alias emptytrash="sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl; sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'"
# See your stuff!
#alias l="ls -alhF"
alias l="gls -alhGF --group-directories-first --color"
function update () {
sudo softwareupdate --all --install --force;
brew update;
brew upgrade;
brew cleanup;
brew doctor;
sudo purge;
}
# Clean up LaunchServices to remove duplicates in the “Open With” menu,
# recursively delete .DS_Store, Icon^M, and .ipynb_checkpoints
alias cleanup="find . \( -type f -name '*.DS_Store' -o -type d -name '.ipynb_checkpoints' -type d -name '.cache' \) -ls -exec rm -rv {} + && find . -name 'Icon' -ls -delete && /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"
alias cpwd="pwd | tr -d '\n' | pbcopy"
# Save GitHub recovery code to clipboard
PATH_TO_TOKENS="$HOME/My\ Drive\ \([email protected]\)/tokens-and-backups"
alias ghpat="cat $PATH_TO_TOKENS/github-pat | pbcopy"
# Rebuild icon cache in macOS
alias rebuildicons="sudo rm -rfv /Library/Caches/com.apple.iconservices.store; sudo find /private/var/folders/ \( -name com.apple.dock.iconcache -or -name com.apple.iconservices \) -exec rm -rfv {} \; ; sleep 3; sudo touch /Applications/* ; killall Dock; killall Finder"
# Re-index everything in Spotlight
alias rebuildspotlight="sudo mdutil -E /"
hash -d gd=~"/Google Drive"
hash -d icloud=~"/Library/Mobile Documents/com~apple~CloudDocs"
hash -d dl=~/Downloads
hash -d dt=~/Desktop
hash -d blog=~/erikr.github.io
hash -d dotfiles=~/dotfiles
# Print contents of comma- or tab-separated value file with perl, column, and less
function csv() {
perl -pe 's/((?<=,)|(?<=^)),/ ,/g;' "$@" | column -t -s, | less -F -S -X -K
}
function tsv() {
perl -pe 's/((?<=\t)|(?<=^))\t/ \t/g;' "$@" | column -t -s $'\t' | less -F -S -X -K
}
# Remove local branches that lack remotes: "git clean local branches"
function gclb() {
git fetch -p;
for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}');
do git branch -D $branch;
done
}
# Lowercase all files
function lowercase() {
for f in *; do mv "$f" "$f.tmp"; mv "$f.tmp" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done
}
# Get distribution of file sizes
function filesizes() {
find . -type f -print0 | xargs -0 ls -l | awk '{ n=int(log($5)/log(2)); if (n<10) { n=10; } size[n]++ } END { for (i in size) printf("%d %d\n", 2^i, size[i]) }' | sort -n | awk 'function human(x) { x[1]/=1024; if (x[1]>=1024) { x[2]++; human(x) } } { a[1]=$1; a[2]=0; human(a); printf("%3d%s: %6d\n", a[1],substr("kMGTEPYZ",a[2]+1,1),$2) }'
}