-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_aliases
149 lines (135 loc) · 4.1 KB
/
.bash_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
# editing dotfiles
alias ea='open ~/.bash_aliases' # edit aliases
alias ep='open ~/.bash_prompt' # edit prompt
alias rl='source ~/.bash_aliases' # reload aliases
# allow sudo with aliases
alias sudo='sudo '
# viewing files
alias o='open .'
if ls --color > /dev/null 2>&1; then # GNU `ls`
alias ls="command ls --color"
else # macOS `ls`
alias ls="command ls -G"
fi
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias wrapon='tput rmam'
alias wrapoff='tput smam'
# navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias cdd='cd ~/Developer'
alias cddt='cd ~/Desktop'
alias cddoc='cd ~/Documents'
alias cddl='cd ~/Downloads'
alias cdapp='cd /Applications'
cl() { cd "$1" && ls; }
cs() { cd "$HOME/Developer/UCLA-CS-$1"; }
# file creation
alias mkdir='mkdir -pv'
mcd() { if [ "$#" -ne 1 ]; then echo "usage: mcd directory"; else mkdir "$1"; cd "$1"; fi;}
# emacs: esc x tetris
mk() {
if [[ "$#" -ne 1 && "$#" -ne 2 ]]; then
echo "usage: mk file [shebang]"
else
touch "$1"
if [ "$#" -ne 1 ]; then
echo -en "$2\n$(cat $1)" > "$1"
fi
chmod +x "$1"
open -t "$1"
fi
}
mksh() { if [ "$#" -ne 1 ]; then echo "usage: mksh file"; else mk "$1" '#!/usr/bin/env bash'; fi; }
mkpy() { if [ "$#" -ne 1 ]; then echo "usage: mkpy file"; else mk "$1" '#!/usr/bin/env python'; fi; }
# hide/show all desktop icons (useful when presenting)
alias hidedt="defaults write com.apple.finder CreateDesktop -bool false && killall Finder"
alias showdt="defaults write com.apple.finder CreateDesktop -bool true && killall Finder"
# show path line by line
alias path='echo -e ${PATH//:/\\n}'
# seasnet
# alias seasnet='ssh [email protected]'
# alias sn='seasnet'
# alias sshfss='/usr/local/bin/sshfs [email protected]: ~/seasnet/ -o volname=SEASNET'
# alias fuse_setup='mkdir ~/seasnet/; sshfss; open ~/SEASNET'
# alias fuse='fuse_setup; while [ $? -ne 0 ]; do ufuse; sleep 1; fuse_setup; open ~/SEASNET; done'
# alias ufuse='umount ~/seasnet/; rmdir ~/seasnet'
fuse() {
LOC="$HOME/Desktop"
DIR="/"
if [ "$#" -ne 2 ]; then
NAME="deterlab"
DEST="[email protected]"
else
NAME="$1"
DEST="$2"
fi
if [ ! -d "$LOC/$NAME-mountpoint" ]; then
echo "Making directory: $LOC/$NAME-mountpoint"
mkdir "$LOC/$NAME-mountpoint"
fi
eval "sshfs $DEST:$DIR $LOC/$NAME-mountpoint -o volname=$NAME"
while [ -d "$LOC/$NAME-mountpoint" ]; do
sleep 1
echo "sleepin"
echo "$LOC/$NAME-mountpoint"
done
cd "$LOC/$NAME"
open "$LOC/$NAME"
}
# git commands
alias g='git'
# cd up to git repo, go back with `cd -`
cdg() {
TEMP_PWD=`pwd`
while ! [ -d .git ]; do
cd ..
done
OLDPWD=$TEMP_PWD
}
gh() {
open `git remote -v |\
grep fetch |\
awk '{print $2}' |\
sed 's/git@/http:\/\//' |\
sed 's/com:/com\//'` |\
head -n1
}
ghcl() {
if [[ "$1" == *"/"* ]]; then
git clone "https://github.com/$1.git"
else
git clone "https://github.com/caziz/$1.git"
fi
}
# macOS commands
alias lock='/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'
# macOS config commands
alias sct='defaults write com.apple.screencapture type'
alias lwt='sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText'
alias cpu='sysctl -n machdep.cpu.brand_string'
alias hw='system_profiler SPHardwareDataType'
alias ikr='defaults write -g InitialKeyRepeat -int 15' # normal minimum is 15 (225 ms)
alias kr='defaults write -g KeyRepeat -int 1' # normal minimum is 2 (30 ms)
# print current finder directory
function pfd { osascript -e 'tell application "Finder"'\
-e "if (${1-1} <= (count Finder windows)) then"\
-e "get POSIX path of (target of window ${1-1} as alias)"\
-e 'else' -e 'get POSIX path of (desktop as alias)'\
-e 'end if' -e 'end tell'; }
# cd to current finder directory
function cdf { cd "`pfd $@`"; }
# open man page in Preview
function pman { man -t "$1" | open -f -a Preview; }
# open man page in x-man-page
function xman {
if [ $# -eq 1 ]; then
open x-man-page://$1;
elif [ $# -eq 2 ]; then
open x-man-page://$1/$2;
fi
}