-
Notifications
You must be signed in to change notification settings - Fork 4
/
.alias
318 lines (270 loc) · 12.5 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
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
#!/usr/bin/env bash
## Common
alias mkdir="mkdir -pv"
alias ls="ls -tr --color=auto -ha --group-directories-first"
alias l="ls++ --potsf -trlFha --group-directories-first "
alias cp="cp -ir"
alias mv="mv -i"
alias ln="ln -i"
#alias rm="rm -Ivr --preserve-root"
alias rm="trash -v"
alias pkill="pkill -9"
alias du="du -ch"
alias ncdu="ncdu -q2"
alias v="vim "
# ds = dusort sorts the current directory items in descending order.
# If a directory is provided as an argument it sorts that instead.
ds () { du -sh "${1-.}"/* | sort -hr ; }
# Source a file if it exists.
try_source() {
[ -f "$1" ] && source "$1"
}
# Test if a command exists.
try_command() {
command -v "$1" >/dev/null 2>&1
}
# Command line head / tail shortcuts (only works on zsh, double check for bash in case bash is called from a zsh shell)
if [ -n "$ZSH" ] && [ ! -n "$BASH" ]; then
# Global aliases
alias -g H="| head"
alias -g T="| tail"
alias -g G="| grep"
alias -g C="| column -t"
alias -g L="| less"
alias -g M="| most"
alias -g B64D="| base64 --decode "
alias -g B64E="| base64 -w 0 "
alias -g RE="2>&1"
alias -g CA="| cat -A"
alias -g NULE="2> /dev/null"
alias -g NUL="> /dev/null"
alias -g P="2>&1 | pygmentize -l pytb"
alias -g S="sudo "
alias -g GS="grep_search "
alias -g UP=" |& up "
# Suffix aliases
alias -s md=vim
alias -s conf=vim
alias -s txt=vim
alias -s jpg=open
alias -s png=open
alias -s pdf=open
alias -s gif=open
#list whats inside packed file
alias -s zip="unzip -l"
alias -s rar="unrar l"
alias -s tar="tar tf"
alias -s tar.gz="echo "
alias -s ace="unace l"
fi
alias free="free -ht"
alias ps="/usr/bin/grc ps auxf"
alias psgrep="ps | grep -v grep | grep -i -e VSZ -e"
alias scp="scp -Cvp -S '$HOME/.extra/ssh-ident/ssh-ident' "
alias rsync="rsync -avSP -e '$HOME/.extra/ssh-ident/ssh-ident' "
alias rsync-del="rsync --delete-before "
# Copies all the files under src directory to dst directory that match the given pattern.
# Also preserves the directories structure (not including empty directories)
cp_with_dirstruct() {
[ "$#" -lt 3 ] && \
echo 'Usage: cp_with_dirstruct "[quoted regex pattern of files to copy (e.g *.txt)]" [src dir] [dst dir]' && \
return 0;
rsync -a --prune-empty-dirs --progress --include='*/' --include="$1" --exclude='*' "$2" "$3" ;
}
# needed because the shell checks only the first word of a command for an alias so
# "sudo somealias" won't work if sudo isn't also an alias
alias sudo="sudo "
alias fn="find . -iname "
alias fd="find . -type d -name"
alias ff="find . -type f -name"
# finds duplicate files in the current folder by checking size first and then md5 hash
alias fdupes="fdupes -dn -r "
alias df="df -Tha --total"
alias h="history"
alias chown="chown --preserve-root"
alias chmod="chmod --preserve-root"
alias chgrp="chgrp --preserve-root"
alias cls=' echo -ne "\033c"'
alias chmodXfolders="find . -type d -exec chmod g+x {} \;"
# canonical hex dump; some systems have this symlinked
command -v hd > /dev/null || alias hd="hexdump -C"
# URL-encode strings
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'
# Coloured df
alias disks='df -ha |\
sed -e "s_/dev/sda[1-9]_\x1b[35m&\x1b[0m_" |\
sed -e "s_/dev/sdb[1-9]_\x1b[33m&\x1b[0m_" |\
sed -e "s_/dev/sd[c-z][1-9]_\x1b[37m&\x1b[0m_" |\
sed -e "s_[.,0-9]*[MG]_\x1b[36m&\x1b[0m_" |\
sed -e "s_[0-9]*%_\x1b[32m&\x1b[0m_" |\
sed -e "s_9[0-9]%_\x1b[31m&\x1b[0m_" |\
sed -e "s_/mnt/[-_A-Za-z0-9]*_\x1b[35;1m&\x1b[0m_"'
alias securewipe_disk="shred --verbose --random-source=/dev/urandom -n1 " # use on /dev/sdxX
# time since installation based on oldest pacman.log entry.
open() { mimeo $1 &> /dev/null &disown; }
alias pm="pacman"
alias pa="pacaur"
alias rg="ranger"
alias extract="atool -x"
# tree command with directories listed first, ignoring .git/ dirs
tree() { command tree --dirsfirst -I '.git' --charset UTF8 -C "$@" | less -RNXF; }
alias less="less -x4SRFX"
alias grep="grep --color=auto -I"
alias grep_search="grep -Eir " # extended regex, recursive, ignore case, show line number
alias ack="ack -i --follow"
alias ag="ag -fi --hidden --numbers --column --stats"
alias sysinfo="inxi -Fzx"
# if nocorrect doesn't exist alias it out
try_command nocorrect || alias nocorrect=""
alias dotfiles='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
g() {
if [ -d '.repo' ]; then
nocorrect repo "$@";
elif [ -d '.dotfiles' ]; then
nocorrect dotfiles "$@";
else
nocorrect git "$@";
fi
}
alias s="g status"
#alias exit="history -c; exit"
# Do something and receive a desktop alert when it completes `sudo apt-get install something | alert`
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias clip_copy='xclip -selection clipboard'
alias clip_paste='xclip -selection clipboard -o'
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
start_detached() { nohup "$@" > /dev/null 2>&1 < /dev/null & }
# source: http://www.commandlinefu.com/commands/view/11774/press-enter-and-take-a-webcam-picture.
alias take_webcam_picture='ffmpeg -y -r 1 -t 3 -f video4linux2 -s sxga -i /dev/video0 -vframes 1 ~/webcam-$(date +%m_%d_%Y_%H_%M).jpeg'
## Navigation just in case:
# cd and ls in one. It changes directory to the first argument given (else to $HOME)
# and lists the files/directories there.
cl() { \cd "${1-$HOME}" && l; }
alias ~="cd $HOME"
alias ..="cd .."
alias ...="cd ../../"
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias cd..="cd .."
#alias cd="cl"
cd() { builtin cd "$@" && _truncated_ls; }
popd() { builtin popd "$@" && _truncated_ls; }
pushd() { builtin pushd "$@" && _truncated_ls; }
## Files
alias diff="colordiff -y --suppress-common-lines " # requires colordiff package
dfl() { diff "$@" | less ; }
mkd() { mkdir -p "$@" && cd "$_"; } # create a new dir and cd into it
alias duplicity="\duplicity --verbosity info --volsize 150 --num-retries 3 --asynchronous-upload --full-if-older-than 90D --log-file /var/log/duplicity.log "
alias duplicity_test="\duplicity --dry-run --no-encryption -v info "
# Mount related
alias mountandroid="mtpfs -o allow_other /media/smartphone"
alias umountandroid="fusermount -u /media/smartphone"
## Network related
# Shows your WAN IP, when you`re sitting behind a router
alias wanip="dig +short myip.opendns.com @resolver1.opendns.com"
alias wanip2="curl ifconfig.me"
alias wanip3="curl icanhazip.com"
alias whois="whois -h whois-servers.net"
alias ifconfig="/usr/bin/grc /sbin/ifconfig"
alias traceroute="/usr/bin/grc traceroute "
alias icurl="curl -I"
alias wget="wget -c"
alias ping="/usr/bin/grc ping -c4"
alias wget_full="wget --random-wait -r -p -e robots=off -U mozilla " # downloads full webpage recursively
alias sniffhttp="ngrep -d 'wlan0' -t '^(GET|POST) ' 'tcp and port 80'" # view HTTP traffic
alias sharedironlan="python2.7 -m SimpleHTTPServer 8080" # share the current dir from port 8080
alias net_listening_connections="lsof -Panl -i tcp -i udp" # show listening connections
alias netstat="/usr/bin/grc /bin/netstat"
alias net="netstat -alputen"
alias net_resolve="netstat -alpute"
alias net_openports="netstat -nape --inet" # display open ports
# SSH
pwd_rounds=500
alias ssh-keygen-ed="ssh-keygen -t ed25519 -a $pwd_rounds -f "
alias ssh-keygen-rsa="ssh-keygen -t rsa -o -b 4096 -a $pwd_rounds -f "
alias ssh-keyrepass="ssh-keygen -p -a $pwd_rounds -f "
alias ssh-key-tonewformat="ssh-keygen -o -p -a $pwd_rounds -f "
unset pwd_rounds
# Youtube
alias youtube-dl='youtube-dl -ci --restrict-filenames -f 22/18/45/35/h264-sd/flv/mp4-sd/mp4/best '
youtube-dlm() {
if [ $# -lt 2 ] ; then
subdir=""
arguments="$@"
else
subdir=$1/
arguments="${@:2}"
fi
youtube-dl --extract-audio --audio-format mp3 -o "$HOME/Downloads/music/$subdir%(title)s.%(ext)s" $arguments
}
alias mplayer_in_term="CACA_DRIVER=ncurses mplayer -cache 5000 -cache-min 0.15 -vo caca -quiet"
## Other
alias screen_cmd="screen -dm sh -c " # runs the cmd that follows inside a detached screen session. Make sure to quote the cmd if there are spaces
alias chromium="chromium --enable-seccomp-sandbox --memory-model=low --purge-memory-button --disk-cache-dir=/dev/shm/chromium-cache --disk-cache-size=300000000"
alias mutt="dtach -A $HOME/.mutt/mutt.session mutt"
alias netbeans="netbeans --laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
alias sscrot="scrot -s /tmp/shot.png"
alias curlpaste="curlpaste -p -e ca "
alias openbox_getOBAPP="obxprop | grep \"^_OB_APP\""
alias valgrind_memcheck="valgrind --leak-check=full --tool=memcheck --track-origins=yes --trace-children=yes "
alias valgrind_massif="valgrind --tool=massif --heap=yes --trace-children=yes --pages-as-heap=yes --massif-out-file=massif.out --time-unit=B "
alias keycast="screenkey -t 0.5 -s medium --no-detach -p bottom --no-systray"
# AV aliases
alias check_rootkits="sudo rkhunter --update; sudo rkhunter --propupd; sudo rkhunter --check"
alias check_virus="clamscan --recursive=yes --infected /home"
alias update_antivirus="sudo freshclam"
alias msfconsole="msfconsole --quiet -x \"db_connect ${USER}@msf\""
alias enable_ptrace="setcap cap_sys_ptrace=eip "
# fortune equality
alias fortune="fortune -e -a"
# Gets a random Futurama quote from slashdot.org(/.)
alias futurama="curl -Is slashdot.org | egrep '^X-(F|B|L)' | cut -d \- -f 2"
alias matrix="tr -c \"[:digit:]\" \" \" < /dev/urandom | dd cbs=\"$COLUMNS\" conv=unblock | GREP_COLOR=\"1;32\" grep --color \"[^ ]\""
alias binclock="watch -n 1 'echo \"obase=2;\`date +%s\`\" | bc'"
alias lotto="shuf -i 1-49 | head -n6 | sort -n | xargs" # randomizer
# if cowsay exists && fortune exists then -> moo
alias moo="try_command cowsay && try_command fortune && fortune -ea | cowsay -f small -e oQ"
# compress/optimize
alias compresspdf="gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -sOutputFile="
alias removeexif="mogrify -strip"
alias mp4tomp3indir='for f in *.mp4; do ffmpeg -loglevel panic -i "$f" -vn -c:a libmp3lame -ar 44100 -ac 2 -ab 192k "${f/%mp4/mp3}"; done'
alias optimizepngsindir='find . -iname "*.png" | xargs pngquant --quality=90-98 --ext ".png" -f '
alias optimizejpgsindir='find . -iname "*.jpg" -o -iname "*.jpeg" | xargs jpegoptim --strip-all'
alias optimizeffdbs='for f in ~/.mozilla/firefox/*.default/*.sqlite; do sqlite3 "$f" "VACUUM;" && sqlite3 "$f" "REINDEX;"; done'
alias resizeallimages='for i in $( ls *.(jpg|png|JPG|PNG|jpeg|JPEG)); do convert -resize 70% $i $i; done'
## Update related
alias upz="pacaur -Syu"
alias cleanz="sudo pacman -Sc;sudo pacman -Rns \"$(pacman -Qtdq)\"; sudo journalctl --vacuum-size=100M;"
alias listdeps="pacman -Qtdq" # lists unused dependencies/leftover packages
alias listallpacks="pacman -Qi | sed -n '/^Name[^:]*: \(.*\)/{s//\1 /;x};/^Installed[^:]*: \(.*\)/{s//\1/;H;x;s/\n//;p}' | sort -nk2"
alias listallexplpacks="pacman -Qeq" # list all explicitly installed packages
alias updatemirrors="reflector --verbose --country Germany -l 200 -p http --sort rate --save /etc/pacman.d/mirrorlist"
alias journalctl_error="journalctl -b -p err"
alias increasetmpfs="mount -o remount,size=4G,noatime /tmp"
echoSection(){
echo "\n-------------------- $@ ---------------------\n"
}
# One Alias to rule them all, One Alias to find them, One Alias to fetch them all and in the staleness update them
updateall(){
dotfiles supdateall && echoSection "Submodules of dotfiles updated";
sudo updatemirrors && echoSection "Mirrors updated";
sudo gem update; sudo gem update --system; sudo gem clean; sudo gem cleanup; echoSection "Gems updated";
upgrade_oh_my_zsh && echoSection "Oh My Zsh updated";
sudo pacman-key --refresh-keys && echoSection " Pacman keys refreshed"
sudo hostsblock && echoSection "HostsBlock updated";
vim +PluginUpdate +qall && echoSection "Vim plugins updated";
update_antivirus && echoSection "Antivirus database updated";
upz && echoSection "System updated";
}
# ack is shorter than ack-grep
if ! type ack > /dev/null; then # Some systems already define `ack`
alias ack=ack-grep
fi
# patch stuff
alias patchfile="patch < "
alias patchdir="patch -p1 < "
alias patchundo="patch -p1 -R < "
# docker
# alias docker_remove_all_stopped_containers="docker rm $(docker ps -a -q)"
# alias docker_remove_all_untagged_images='docker rmi $(docker images | grep "^<none>" | awk "{print $3}")'