############################################################################## # ~/.aliases file by luc #+ This file contains aliases and functions which hopefully work not only in #+ bash (I did not test anything else by now). #+ Many thanks to the people from #+ http://crunchbanglinux.org/forums/topic/1093/post-your-bashrc/ ############################################################################## ############################################################################## # alias (all systems) ############################################################################## alias src='. $HOME/.bashrc' #source bashrc to see changes alias unnote='PROMPT_COMMAND=ret=\$?' # undo the 'note' function. alias tgz='tar -czv --exclude .DS_Store' alias tbz2='tar -cjv --exclude .DS_Store' alias grep='grep --color=auto' #color alias up='date +%F" $(uptime)"' # info for record ceeping with date alias lr='tree -Chuap' # replacement for ls -lR alias histhead='history | awk '\''{a[$2]++}END{for(i in a){print a[i]" "i}}'\'' | sort -rn | head' ############################################################################## # alias (connect to remote) ############################################################################## alias my_sftp='sftp user@remote.host' # anonymized alias my_ssh='ssh -t -l user remote.host' # anonymized ############################################################################## # alias (system specific) ############################################################################## if [ `uname` = "Darwin" ] ; then # (Mac OS X, 10.6) alias ll='ls -l' alias ls='ls -G' #color alias battery='system_profiler SPPowerDataType | sed -n "3,4p;14,25p"' #info about battery alias 7z='/Applications/7zX.app/Contents/Resources/7za' #i did not find a cli for 7z alias octave='/Applications/Octave.app/Contents/MacOS/Octave.app' alias gvim='open -aVim' #MacVim as gvim alias igo='wine $HOME/.wine/drive_c/Program\ Files/igowin/igowin.exe' #play go alias dl='cd $HOME/Downloads && wget' alias vi=/Applications/editoren/Vim.app/Contents/MacOS/Vim alias bk='[ ! -f $HOME/Documents/Dateien\ `date +%F`.tar.bz2 ] && tar -cvjC $HOME/Documents -f $HOME/Documents/Dateien\ `date +%F`.tar.bz2 --exclude .DS_Store Dateien' else # we are on GNU/Linux hopefully alias ll='ls -l' alias ls='ls --color=auto' fi ############################################################################## # functions (all systems) ############################################################################## note () { #execute $@ befor printing the prompt (PS1); 'unnote' is an alias if [ "$1" = -p ]; then echo "note \"$PROMPT_COMMAND\"" elif [ "$1" = -r ]; then PROMPT_COMMAND="${@:2}" elif [ -z "$PROMPT_COMMAND" ]; then PROMPT_COMMAND="${@}" else PROMPT_COMMAND="${PROMPT_COMMAND} ; ${@}" fi } comp () { #compare the speed of two ($1, $2) commands (loop $3 times) if [ $# -ne 3 ]; then return 1; fi type $1 >/dev/null 2>&1 || return 2 type $2 >/dev/null 2>&1 || return 3 printf 1 time for ((i=0; i<${3:-10}; i++)) ; do $1 ; done >/dev/null 2>&1 printf 2 time for ((i=0; i<${3:-10}; i++)) ; do $2 ; done >/dev/null 2>&1 } hira () { #summed up info about trees at "$@" (or ".") local count size sizeH if [ "$1" ]; then for file; do count=$(tree -ai "$file" | tail -n 1) #need tree to be installed size_=$(du -s "$file" | tail -n 1) #darwin/OSX no '-b=1' sizeH=$(du -hs "$file" | tail -n 1) echo "$file: ${count}, ${sizeH%%$'\t'*} ($((512*${size_%%$'\t'*})))" #darwin/OSX: '512' done echo "" fi count=$(tree -ai "$@" | tail -n 1) #need tree to be installed size_=$(du -cs "$@" | tail -n 1) #darwin/OSX no '-b=1' sizeH=$(du -chs "$@" | tail -n 1) echo "${count}, ${sizeH%%$'\t'*} ($((512*${size_%%$'\t'*})))" #darwin/OSX: '512' } 2>/dev/null # idea from http://crunchbanglinux.org/forums/topic/1093/post-your-bashrc/ uz () { #unzip archives automatically if [ ! -f "$1" ] ; then echo "uz: '$1' is not a valid file."; return 1; fi case "$1" in *.tar.bz2|*.tbz2) tar xvjf "$1" ;; *.tar.gz|*.tgz|*.tar.Z) tar xvzf "$1" ;; *.tar.xz) tar xvJf "$1" ;; *.tar) tar xvf "$1" ;; *.bz2) bunzip2 "$1" ;; *.rar) rar x "$1" ;; *.jar) unzip "$1" ;; *.gz) gunzip "$1" ;; *.zip) unzip "$1" ;; *.Z) uncompress "$1" ;; *.7z) 7z x "$1" ;; *.xz) xz x "$1" ;; *.exe) cabextract "$1" ;; *) echo "uz: Don't know how to extract '$1'." 1>&2; return 1 ;; esac } 7z_help () { echo "7z a|b|d|e|l|t|u|x [OPTIONS] ARCHIVE [FILES ...]" echo "-mx[0-9]" echo "-t7z | -tgzip | -tzip | -tbzip2 | -ttar | -tiso | -tudf" } cmdfu () { wget --quiet -O - "http://www.commandlinefu.com/commands/matching/$@/$(echo -n "$@" | openssl base64)/plaintext"; } # idea from http://crunchbanglinux.org/forums/topic/1093/post-your-bashrc/ weather() { #best by now elinks -dump "google.com/search?hl=en&q=weather+${1:-munich}" | \ sed -n '/Weather for/,${/Weather/{s/^ *//;s/-.*//;};/iGoogle/d;s/|.*//;p;/Humidity/q;}' } wiki () { dig +short txt $1.wp.dg.cx; } ############################################################################### # TODO ############################################################################### #alias cp='cp -i' #alias rm='rm -i' #alias mv='mv -i'