# .bashrc # Some minimal API expected by sourced files # XXX: check for alias collision _diralias () { local target=$(echo $* | sed -s "s| |/|g") test "$(pwd)" = "$(eval echo "$(dirs +1 2>/dev/null)")" && popd -n &>/dev/null test "${target}" = "$(eval echo "$(dirs +0)")" || pushd "${target}" >/dev/null pwd } diralias () { alias "$(basename "$1")=_diralias $1" # using loose depth from the beginning unnecessarily clutter the offer, # so this way, albeit complicated, convenient traversal is achieved # XXX could -G be used instead? complete -o nospace -C \ "f(){ test \"\$3\" != \"$(basename "$1")\" || \ find -L \"${1%%* }/\${2%\${2##*/}}\" \ -mindepth 1 -maxdepth 1 -type d -name \"\${2##*/}*\" \ -printf \"\${2%\${2##*/}}%P\\n\"; }; f" \ "$(basename "$1")" } if test -n "${XAUTHORITY:-}"; then _linkalias () { gnome-open "$(printf "$1" "${@:2}")" } else _linkalias () { elinks "$(printf "$1" "${@:2}")" } fi linkalias () { alias "$1=_linkalias $2"; } # Source the other common definitions for f in /etc/profile \ $(find ~ -maxdepth 1 -name '.bashrc-*' \! -name '.bashrc-priv-*'); do test -f "${f}" && source "${f}" || : done # User specific aliases and functions set -o vi shopt -s histappend HISTSIZE=60000 HISTCONTROL=ignoreboth # subshell to avoid triggering DEBUG. (src: http://stuff.lhunath.com/.bashrc) PROMPT_COMMAND='(history -a)' PS1='\[\033[01;34m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ ' ACK=ack test "$(ack --version | head -n1 | sed 's|^ack\s\([0-9]\+\).*|\1|')" -ge 2 \ || ACK+=" -a" # http://ruslanspivak.com/2010/11/25/bash-history-incremental-search-forward/ # ^X goes in to the way of vim's omnicompletion stty stop ^P # op(t)inioned commands alias tree='tree -a' alias mc='LESS="-RSX" mc' alias tmux='tmux -2' alias acka='$ACK --follow' # internal, debug, etc. alias hist-del-last='history -d $(history 1 | cut -d" " -f2)' # historical NOOP alias int-usage='echo "usage: $FUNCNAME "' # dir aliases (use either as "gmy" or "cd $(gmy)" or, e.g., "gmy dotfiles") diralias ~/wrkspc diralias ~/wrkspc/gmy diralias ~/wrkspc/gwork # internal, debug, etc. debug-argsep () { while [ $# -ne 0 ]; do echo $1; shift done } # proper functions cdup () { local up="." for i in $(seq 1 $1); do up+="/.."; done cd "${up}" 2>/dev/null && pwd || : unset up } cdmk () { cd "$1" 2>/dev/null || { mkdir "$1"; cd "$1";} } # Jim Meyring's take on "display the programs with W and X memory" # http://lists.fedoraproject.org/pipermail/devel/2013-April/181747.html sec-wx-mem () { grep -lE '^[0-9a-f-]+ .wx' /proc/*/maps 2>/dev/null \ | perl -ne 'm!^(/proc/(\d+))/.*! and printf qq(%5d %s\n), $2, `cat $1/cmdline`' \ | tr '\0' ' ' } ack-intersection () { [ $# -ne 2 ] && int-usage "1st-regexp" "2nd-regexp" && return comm <($ACK -l --follow "$1" | sort) <($ACK -l --follow "$2" | sort) -12 } hist-grep () { hist-del-last # omit hist-grep invocation grep $* -- ~/.bash_history } img-diff () { [ $# -ne 2 ] && int-usage "1st-img" "2nd-img" && return #xloadimage <(gm compare "$1" "$2" -highlight-color red -highlight-style threshold -file -) #xloadimage <(compare "$1" "$2" -highlight-color violet -lowlight-color darkgray -compose threshold -) #xloadimage <(compare "$1" "$2" -highlight-color violet -lowlight-color darkgray \ # -compose threshold jpg:- | convert jpg:- -fuzz 2% -fill red -opaque '#915e99' png:-) xloadimage <(compare "$1" "$2" -highlight-color violet -lowlight-color darkgray -compose threshold -) } img-qr () { local title="Piped: " [ $# -ge 1 ] \ && { input="$1"; title="$1"; } \ || { input=$(&1 | ${PAGER}" trap "_preexec_flag=0; trap - RETURN;" RETURN return 2 ;; esac } preexec_install