Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pretty bash prompt

The new bash PS1 is inspired by the vim powerline.

The first segment is the id of the current command in the history. The
second segment is the user and host, this segment is grey when the shell
is local and blue when it exists through ssh. The third segment is the
work directory. The last segment appears only when the current directory
is a git, hg or svn repositoty and display the current branch.
  • Loading branch information...
commit 95fcbec5c6a9a2090b6ca402153bac94ba0ed0f6 1 parent e5ab4b2
@jbarnoud authored
Showing with 51 additions and 2 deletions.
  1. +2 −1  _bashrc
  2. +48 −0 _prompt.sh
  3. +1 −1  _vim/bundle/fugitive
View
3  _bashrc
@@ -153,7 +153,8 @@ alias xo="xdg-open"
alias dfc="dfc -f"
#export PS1='\e[01m\e[07m\u@\h \w$(__git_ps1 " (%s)") \$\e[0m\e[0m '
-export PS1='(\!)\u@\h \w$(__git_ps1 " (%s)") \$ '
+#export PS1='(\!)\u@\h \w$(__git_ps1 " (%s)") \$ '
+source ~/.prompt.sh
# Color in less
# need ~/.lessfilter and python package Pygments
View
48 _prompt.sh
@@ -0,0 +1,48 @@
+section_hist=34
+section_user=242
+section_dir=237
+section_end=16
+nocol='\[\033[m\]'
+if [[ -n ${SSH_CLIENT} ]]
+then
+ section_user=17
+fi
+
+prompt_git() {
+ git branch &>/dev/null || return 1
+ HEAD="$(git symbolic-ref HEAD 2>/dev/null)"
+ BRANCH="${HEAD##*/}"
+ [[ -n "$(git status 2>/dev/null | \
+ grep -F 'working directory clean')" ]] || STATUS="!"
+ printf ' ⭠ git:%s' "${BRANCH:-unknown}${STATUS}"
+}
+prompt_hg() {
+ hg branch &>/dev/null || return 1
+ BRANCH="$(hg branch 2>/dev/null)"
+ [[ -n "$(hg status 2>/dev/null)" ]] && STATUS="!"
+ printf ' ⭠ hg:%s' "${BRANCH:-unknown}${STATUS}"
+}
+prompt_svn() {
+ svn info &>/dev/null || return 1
+ URL="$(svn info 2>/dev/null | \
+ awk -F': ' '$1 == "URL" {print $2}')"
+ ROOT="$(svn info 2>/dev/null | \
+ awk -F': ' '$1 == "Repository Root" {print $2}')"
+ BRANCH=${URL/$ROOT}
+ BRANCH=${BRANCH#/}
+ BRANCH=${BRANCH#branches/}
+ BRANCH=${BRANCH%%/*}
+ [[ -n "$(svn status 2>/dev/null)" ]] && STATUS="!"
+ printf ' ⭠ svn:%s' "${BRANCH:-unknown}${STATUS}"
+}
+prompt_vcs() {
+ prompt_git || prompt_svn || prompt_hg
+}
+
+trans_color() {
+ before_color=$1
+ after_color=$2
+ echo "\[\e[38;5;${before_color}m\]\[\e[48;5;${after_color}m\]⮀\[\e[m\]\[\e[48;5;${after_color}m\]"
+}
+export PS1="\[\e[48;5;${section_hist}m\]"'\!'$(trans_color ${section_hist} ${section_user})'\u@\h'$(trans_color ${section_user} ${section_dir})'\W$(prompt_vcs)'$(trans_color ${section_dir} ${section_end})${nocol}
+
2  _vim/bundle/fugitive
@@ -1 +1 @@
-Subproject commit 3b278277e0b46711c30a3d1a0083e527b2fb98ed
+Subproject commit 9ebff45853affc71f821551bf22782f8d6a04f1e
Please sign in to comment.
Something went wrong with that request. Please try again.