-
Notifications
You must be signed in to change notification settings - Fork 0
/
alias
216 lines (184 loc) · 5.27 KB
/
alias
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
# Aliases
# =======
# Make destructive commands a little safer.
#alias rm="rm -i"
alias mv="mv -i"
alias cp="cp -i"
# Make human readable output default for a few commands.
alias df="df -h"
alias du="du -sh"
# Map vi to vim
alias vi="vim"
# 'ls' Aliases. Colourise output by default.
# long:
alias l="ls"
alias ll="ls -lh"
alias lll="ls -lh | less"
# 1:
alias l1="ls -1"
alias l1l="ls -1 | less"
# all:
alias la="ls -a"
alias lla="ls -lah"
alias llahl="ls -lah | less"
alias lal="ls -a | less"
# 1 & all:
alias l1a="ls -1a"
alias l1al="ls -1a | less"
alias mplayer="mplayer -fs -zoom"
alias be="bundle exec "
# Functions
# =========
sshfs(){
FOLDER=$(echo ${@} | cut -d ':' -f 1)
mkdir -p /Volumes/${FOLDER}
`which sshfs` -o transform_symlinks $@ /Volumes/${FOLDER}
echo "Volume mounted on /Volumes/${FOLDER}"
pushd /Volumes/${FOLDER}
}
alias unmount_all="pushd ~/ &>/dev/null && find /Volumes -mindepth 1 -maxdepth 1 -type d -exec umount {} \; && popd &>/dev/null"
# forever() executes its argument in an infinite loop. Useful for
# monitoring things. Note it will not work with aliases.
forever() {
while true; do
clear
$@
sleep 1
done
}
# Overwrite svn diff to get colors
svn() {
if [ "$1" = "diff" ]; then
/usr/bin/svn "$@" | vim -R -c 'set nonu' -
else
/usr/bin/svn "$@"
fi
}
cal(){
if [ "$1" = `date +%Y` ]; then
/usr/bin/cal $1 | sed -e "s/$(date +%e) /`echo -e \\\033\[31m`&`echo -e \\\033\[0m`/g" -e "s/$(date +%B)/`echo -e \\\033\[5\;33m`&`echo -e \\\033\[0m`/g"
elif [ $# = 0 ]; then
/usr/bin/cal | awk '{ print " "$0; getline; print " Mo Tu We Th Fr Sa Su"; getline; if (substr($0,1,2) == " 1") print " 1 "; do { prevline=$0; if (getline == 0) exit; print " " substr(prevline,4,17) " " substr($0,1,2) " "; } while (1) }' | sed -E '1,$'"s/(^|[^0-9])($(date +%e))([^0-9]|$)/\1$(echo -e '\033[1;31m')\2$(echo -e '\033[0m')\3/";
else
/usr/bin/cal "$@";
fi
}
notify()
{
# run a subshell in the foreground in order to protect
# the current (shell) process from the second exec
(
# fork another shell in the background
exec $SHELL -c '
# wait for parent to exit
while [ `ps -o ppid= $$` -ne 1 ] ; do
sleep 1;
done;
# echo an alarm escape to the terminal
echo -ne "\a" \
' &
# execute the supplied command
# this replaces the subshell process
exec "$@"
)
}
# Make directory and move into it
mkcd(){
mkdir -p "$@" && eval cd "\"\$$#\"";
}
git_diff(){
git diff --no-ext-diff -w "$@" | vim -R -
}
diffdir(){
vimdiff <(cd $1 && find . | sort) <(cd $2 && find . | sort)
}
# extract files. Ignore files with improper extensions.
extract(){
local x
ee() { # echo and execute
echo "$@"
$1 "$2"
}
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) ee "tar xvjf" $1 ;;
*.tar.gz) ee "tar xvzf" $1 ;;
*.bz2) ee "bunzip2" $1 ;;
*.rar) ee "unrar x" $1 ;;
*.gz) ee "gunzip" $1 ;;
*.tar) ee "tar xvf" $1 ;;
*.tbz2) ee "tar xvjf" $1 ;;
*.tgz) ee "tar xvzf" $1 ;;
*.zip) ee "unzip" $1 ;;
*.Z) ee "uncompress" $1 ;;
*.7z) ee "7z x" $1 ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
up(){
local d=""
limit=$1
for ((i=1 ; i <= limit ; i++))
do
d=$d/..
done
d=$(echo $d | sed 's/^\///')
if [ -z "$d" ]; then
d=..
fi
cd $d
}
psgrep(){
ps aux | grep $(echo $1 | sed "s/^\(.\)/[\1]/g")
}
tor() {
export IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')
/usr/X11/bin/xhost + ${IP}
docker run \
--rm --name tor \
-e DISPLAY=${IP}:0 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v $(pwd):/usr/local/bin/Browser/Downloads/ \
jess/tor-browser
/usr/X11/bin/xhost - ${IP}
unset IP
}
# Jumping with symlinks
# http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
export MARKPATH=$HOME/.marks
function jump {
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}
function mark {
mkdir -p "$MARKPATH";
ln -s "$(pwd)" "$MARKPATH/$1"
}
function unmark {
rm -i "$MARKPATH/$1"
}
function marks {
if [[ $(uname) == "Darwin" ]]; then
\ls -l "$MARKPATH" | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}'
else
ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
fi
}
# End of jumping with symlinks
func mfaws() {
# docker run --rm -v ~/.aws/:/root/.aws pbar1/mfaws:latest --force -t $(ykman oath accounts code -s 'Amazon Web Services')
$GOPATH/bin/mfaws --force -t $($(brew --prefix)/bin/ykman oath accounts code 'Amazon Web Services' -s)
}
# now prints out the current time in the RFC3339 format
function now(){
date -u +"%Y-%m-%dT%H:%M:%SZ"
}
# function aws() {
# docker run -v $HOME/.aws:/root/.aws:ro --rm amazon/aws-cli $@
# }
function presign() {
aws s3 cp $1 s3://frankywahl/$1
AWS_REGION=$(aws s3api get-bucket-location --bucket frankywahl | jq -r '.LocationConstraint' | sed 's/null/us-east-1/g') aws s3 presign s3://frankywahl/$1
}