summaryrefslogtreecommitdiffstats
path: root/bashrc
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2009-06-23 01:30:06 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2009-06-23 01:30:06 +0200
commita38692c5b380de933a0e9ff90aa605e61490fadd (patch)
tree21d9c4ce23c4c4cca0b374f66e29072b40270571 /bashrc
parent3513d65b8b63f639059eb1909eb490cd3dcf2c43 (diff)
downloaddotfiles-a38692c5b380de933a0e9ff90aa605e61490fadd.tar.gz
dotfiles-a38692c5b380de933a0e9ff90aa605e61490fadd.tar.xz
dotfiles-a38692c5b380de933a0e9ff90aa605e61490fadd.zip
prompt added
added customized gentoo-prompt with returncode, svn/git magic
Diffstat (limited to 'bashrc')
-rw-r--r--bashrc/common/prompt.sh100
-rw-r--r--bashrc/main.sh2
2 files changed, 101 insertions, 1 deletions
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