summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2009-07-05 17:15:37 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2009-07-05 17:15:37 +0200
commit45a8ed9313bef55fdffce6d3932947b62467028d (patch)
treeb52682db6e9b4ef86be0b7cf6e07b324a34f026f
parent74f428e564d09cb9c8d9c5de8c17f5e169d7b6f6 (diff)
downloaddotfiles-45a8ed9313bef55fdffce6d3932947b62467028d.tar.gz
dotfiles-45a8ed9313bef55fdffce6d3932947b62467028d.tar.xz
dotfiles-45a8ed9313bef55fdffce6d3932947b62467028d.zip
update prompt to by fully generated by propt_command
using prompt command to gernerate a static prompt to support correct bash line wrapping
-rw-r--r--bashrc/common/prompt.sh176
1 files changed, 89 insertions, 87 deletions
diff --git a/bashrc/common/prompt.sh b/bashrc/common/prompt.sh
index a2b98a4..8c463dd 100644
--- a/bashrc/common/prompt.sh
+++ b/bashrc/common/prompt.sh
@@ -3,98 +3,100 @@
_load group prompt
_load node prompt
-returncolor() {
- rc=$?
-
- if [[ $1 -eq 0 ]]; then
- [[ $rc -eq 0 ]] && echo 0
+export PS2="$(pcolor lblue)> $(pcolor)"
+export PS3="$(color lblue)#? $(color)"
+
+__make_prompt() {
+ local PS1UH PS1D PS1R PS1F PS1P PS1BO PS1BC rc=$? s
+
+ # username + nodename
+ if [[ $(id -u) -eq 0 ]]; then
+ PS1UH="$(pcolor lred)\h$(pcolor)"
+ else
+ PS1UH="$(pcolor lgreen)\u@\h$(pcolor)"
+ fi
+
+ # working directory
+ PS1D="$(pcolor lblue)$(pwd -P)$(pcolor)"
+
+ # return code
+ if [[ $rc -eq 0 ]]; then
+ PS1R="$(pcolor lgreen)0$(pcolor)"
+ else
+ PS1R="$(pcolor red)${rc}$(pcolor)"
+ fi
+
+ # environment flags
+ [[ "${TERM}" == "screen" ]] && PS1F="${PS1F}$(pcolor lcyan)s$(pcolor)"
+
+ # prompt character
+ PS1P="$(pcolor lblue)\$ $(pcolor)"
+
+ # open/closing brackets
+ PS1BO="$(pcolor lgray)[$(pcolor)"
+ PS1BC="$(pcolor lgray)]$(pcolor)"
+
+ if [[ -d ".svn" ]] ; then
+ local r=
+ if hash svnversion >/dev/null 2>&1 ; then
+ r=$(svnversion 2>/dev/null )
else
- [[ $rc -ne 0 ]] && echo $rc
+ r=$(svn info | sed -n -e '/^Revision: \([0-9]*\).*$/s//\1/p' )
fi
- return $rc
-}
-
-# username + nodename
-if [[ $(id -u) -eq 0 ]]; then
- PS1UH="$(pcolor lred)\h$(pcolor)"
-else
- PS1UH="$(pcolor lgreen)\u@\h$(pcolor)"
-fi
-
-# working directory
-PS1D="$(pcolor lblue)\w$(pcolor)"
-
-# return code
-PS1R="$(pcolor red)\$(returncolor 1)$(pcolor lgreen)\$(returncolor 0)$(pcolor)"
-
-# environment flags
-[[ "${TERM}" == "screen" ]] && PS1F="${PS1F}$(pcolor lblue)s$(pcolor)"
-
-# prompt character
-PS1P="$(pcolor lblue)\$ $(pcolor)"
-
-# open/closing brackets
-PS1BO="$(pcolor lgray)[$(pcolor)"
-PS1BC="$(pcolor lgray)]$(pcolor)"
-
-# git/svn magic
-ps_scm_f() {
- local s=
-
- if [[ -d ".svn" ]] ; then
- local r=$(svn info | sed -n -e '/^Revision: \([0-9]*\).*$/s//\1/p' )
- s="$(color yellow)r$r$(color red)$(svn status | grep -q -v '^?' && echo -n "*" )"
- else
- local d=$(git rev-parse --git-dir 2>/dev/null ) b= r= a=
- if [[ -n "${d}" && "${d}" != "." && ! -f "${d}/../.promptignore" ]] ; then
- if [[ -d "${d}/../.dotest" ]] ; then
- if [[ -f "${d}/../.dotest/rebase" ]] ; then
- r="rebase"
- elif [[ -f "${d}/../.dotest/applying" ]] ; then
- r="am"
- else
- r="???"
- fi
- b=$(git symbolic-ref HEAD 2>/dev/null )
- elif [[ -f "${d}/.dotest-merge/interactive" ]] ; then
- r="rebase-i"
- b=$(<${d}/.dotest-merge/head-name)
- elif [[ -d "${d}/../.dotest-merge" ]] ; then
- r="rebase-m"
- b=$(<${d}/.dotest-merge/head-name)
- elif [[ -f "${d}/MERGE_HEAD" ]] ; then
- r="merge"
- b=$(git symbolic-ref HEAD 2>/dev/null )
- elif [[ -f "${d}/BISECT_LOG" ]] ; then
- r="bisect"
- b=$(git symbolic-ref HEAD 2>/dev/null )"???"
- else
- r=""
- b=$(git symbolic-ref HEAD 2>/dev/null )
- fi
-
- if git status | grep -q '^# Changed but not updated:' ; then
- a="${a}*"
- fi
-
- if git status | grep -q '^# Changes to be committed:' ; then
- a="${a}+"
- fi
-
- if git status | grep -q '^# Untracked files:' ; then
- a="${a}?"
- fi
-
- b=${b#refs/heads/}
- b=${b// }
- [[ -n "${r}${b}${a}" ]] && s="$(color lgreen)${r:+${r}:}$(color yellow)${b}$(color red)${a}"
+ s="$(pcolor yellow)r$r$(pcolor red)$(svn status | grep -q -v '^?' && echo -n "*" )"
+ else
+ local d=$(git rev-parse --git-dir 2>/dev/null ) b= r= a=
+ if [[ -n "${d}" && "${d}" != "." && ! -f "${d}/../.promptignore" ]] ; then
+ if [[ -d "${d}/../.dotest" ]] ; then
+ if [[ -f "${d}/../.dotest/rebase" ]] ; then
+ r="rebase"
+ elif [[ -f "${d}/../.dotest/applying" ]] ; then
+ r="am"
+ else
+ r="???"
fi
+ b=$(git symbolic-ref HEAD 2>/dev/null )
+ elif [[ -f "${d}/.dotest-merge/interactive" ]] ; then
+ r="rebase-i"
+ b=$(<${d}/.dotest-merge/head-name)
+ elif [[ -d "${d}/../.dotest-merge" ]] ; then
+ r="rebase-m"
+ b=$(<${d}/.dotest-merge/head-name)
+ elif [[ -f "${d}/MERGE_HEAD" ]] ; then
+ r="merge"
+ b=$(git symbolic-ref HEAD 2>/dev/null )
+ elif [[ -f "${d}/BISECT_LOG" ]] ; then
+ r="bisect"
+ b=$(git symbolic-ref HEAD 2>/dev/null )"???"
+ else
+ r=""
+ b=$(git symbolic-ref HEAD 2>/dev/null )
+ fi
+
+ if git status | grep -q '^# Changed but not updated:' ; then
+ a="${a}*"
+ fi
+
+ if git status | grep -q '^# Changes to be committed:' ; then
+ a="${a}+"
+ fi
+
+ if git status | grep -q '^# Untracked files:' ; then
+ a="${a}?"
+ fi
+
+ b=${b#refs/heads/}
+ b=${b// }
+ [[ -n "${r}${b}${a}" ]] && s="$(pcolor lgreen)${r:+${r}:}$(pcolor yellow)${b}$(pcolor red)${a}$(pcolor)"
fi
+ fi
- echo -n "${s:+${s} }"
-}
+ if [[ -n "${s}" ]]; then
+ s="${s} "
+ fi
-export PS1="${PS1UH} ${PS1BO}${PS1R}${PS1F}${PS1BC} ${PS1D} \$(ps_scm_f)${PS1P}"
+ export PS1="${PS1UH} ${PS1BO}${PS1R}${PS1F}${PS1BC} ${PS1D} ${s}\n${PS1P}"
+}
-unset PS1UH PS1D PS1R PS1F PS1P PS1BO PS1BC
+export PROMPT_COMMAND="__make_prompt"