diff options
-rw-r--r-- | .bashrc | 41 |
1 files changed, 38 insertions, 3 deletions
@@ -45,9 +45,40 @@ 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\]\$ ' +# SMART EXIT CODE INFO (by jpokorny) +# +# demo@system:~[0|..]$ true +# demo@system:~[0|00]$ +# demo@system:~[0|..]$ false +# demo@system:~[0|01]$ +# demo@system:~[0|..]$ ^C +# demo@system:~[0|..]$ trueue +# > bash: trueue: command not found +# demo@system:~[0|7f]$ kinit +# demo@system:~(0|00)$ +# +# see XXX at preexec (tightly connected) +# XXX subshell to avoid triggering DEBUG? (src: http://stuff.lhunath.com/.bashrc) +#PROMPT_COMMAND='(trap - DEBUG; history -a)' +PROMPT_COMMAND='(history -a; [ ${_postexec_flag} -ne 0 ]) \ + && _postexec_flag_=${_postexec_flag} || _postexec_flag_=0' +PS1='\[\033[01;34m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\[\033[$( + _ret=$? + [ -n "${MC_SID}" ] && _mc_char="#" || _mc_char="|" + klist -s && { _lpar="("; _rpar=")"; } || { _lpar="["; _rpar="]"; } + git rev-parse --git-dir &>/dev/null \ + && { git diff-files --quiet \ + && { git diff-index --quiet --cached HEAD \ + && _head=$(git rev-parse --abbrev-ref HEAD) \ + || _head=C; } \ + || _head=S; } \ + || _head="$(($(dirs -p | head -n9 | wc -l) - 1))" + _head+=${_mc_char} + [ "${_postexec_flag_}" -eq 0 ] && printf "0m\]${_lpar}${_head}..${_rpar}" || { + [ ${_ret} -eq 0 ] && printf "1;34m\]" || printf "1;35m\]" + printf "${_lpar}${_head}%0.2x${_rpar}" "${_ret}" + } +)$\[\033[00m\] ' ACK=ack test "$(ack --version | head -n1 | sed 's|^ack\s\([0-9]\+\).*|\1|')" -ge 2 \ @@ -140,15 +171,19 @@ img-qr () { # prexec stuff _preexec_flag=0 +_postexec_flag=0 # idea is simple: auto-paginate output of selected commads that cannot do it # on their own # XXX: hacky, not exactly sure why this (and so far only this) works :) +# BUG: once something paginated, sole Enter will repeat last command preexec() { + _postexec_flag=0 local cmd=${1%% *} #test ${_preexec_flag} -eq 0 && test ${BASH_SUBSHELL} -eq 0 \ # || { _preexec_flag=0; return 0; } test ${BASH_SUBSHELL} -eq 0 && [[ ! "${1}" =~ .*\|.* ]] \ || { _preexec_flag=0; return 0; } + _postexec_flag=1 case "$1" in colordiff\ *|\ diff\ *|\ |