From a38692c5b380de933a0e9ff90aa605e61490fadd Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 23 Jun 2009 01:30:06 +0200 Subject: prompt added added customized gentoo-prompt with returncode, svn/git magic --- bashrc/common/prompt.sh | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ bashrc/main.sh | 2 +- 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 bashrc/common/prompt.sh (limited to 'bashrc') diff --git a/bashrc/common/prompt.sh b/bashrc/common/prompt.sh new file mode 100644 index 0000000..0d16f1d --- /dev/null +++ b/bashrc/common/prompt.sh @@ -0,0 +1,100 @@ +# command prompt + +_load group prompt +_load node prompt + +returncolor() { + rc=$? + + if [[ $1 -eq 0 ]]; then + [[ $rc -eq 0 ]] && echo 0 + else + [[ $rc -ne 0 ]] && echo $rc + 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}" && ! -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}" + fi + fi + + echo -n "${s:+${s} }" +} + +export PS1="${PS1UH} ${PS1BO}${PS1R}${PS1F}${PS1BC} ${PS1D} \$(ps_scm_f)${PS1P}" + +unset PS1UH PS1D PS1R PS1F PS1P PS1BO PS1BC diff --git a/bashrc/main.sh b/bashrc/main.sh index 3aa8722..b2edc14 100644 --- a/bashrc/main.sh +++ b/bashrc/main.sh @@ -104,7 +104,7 @@ _load common color _load common dircolors # command prompt -#_load common prompt +_load common prompt # screen shelltitle magic _load common screen -- cgit v1.2.3