summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2014-08-18 23:11:14 +0200
committerJan Pokorný <jpokorny@redhat.com>2014-08-18 23:12:27 +0200
commit111a467d4e331e805e49904af0cd8b9b77fd7af7 (patch)
tree66da4905c204989c230dcfeb55cd920decd42a8c
parentdf905a177801e5372bff69e239f28e5c4118be5d (diff)
downloaddotfiles-111a467d4e331e805e49904af0cd8b9b77fd7af7.zip
dotfiles-111a467d4e331e805e49904af0cd8b9b77fd7af7.tar.gz
dotfiles-111a467d4e331e805e49904af0cd8b9b77fd7af7.tar.xz
Bash config: tweak cmd prompt: status+non/mc+kerb.+dirs/git
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r--.bashrc41
1 files changed, 38 insertions, 3 deletions
diff --git a/.bashrc b/.bashrc
index 80769f5..2f32f5a 100644
--- a/.bashrc
+++ b/.bashrc
@@ -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\ *|\