iiska (owner)

Fork Of

gist: 31631 by henrik Git branch and dirty state ...

Revisions

gist: 47408 Download_button fork
public
Description:
http://www.otit.fi/~iiska/bash_prompt-20090115.png
Public Clone URL: git://gist.github.com/47408.git
Embed All Files: show embed
.bashrc #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# .bashrc
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
[ -z "$PS1" ] && return
 
# http://en.tldp.org/HOWTO/Bash-Prompt-HOWTO/x869.html
function prompt_command {
hostnam=$(hostname -s)
usernam=$(whoami)
#returnvalue=$(([ $? -eq 0 ] && echo "\[\033[0;32m\]"☺) || echo "\[\033[0;31m\]"☹)
 
# Find the width of the prompt:
TERMWIDTH=${COLUMNS}
 
# Add all the accessories below ...
local temp="--(${usernam}@${hostnam})(${PWD/#$HOME/~}$(parse_git_branch 1))--"
 
let fillsize=${TERMWIDTH}-${#temp}
if [ "$fillsize" -gt "0" ]
then
fill="────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
# It's theoretically possible someone could need more
# dashes than above, but very unlikely! HOWTO users,
# the above should be ONE LINE, it may not cut and
# paste properly
fill="${fill:0:${fillsize}}"
fi
}
 
PROMPT_COMMAND=prompt_command
 
# http://henrik.nyh.se/2008/12/git-dirty-prompt
function parse_git_dirty {
    local ret
    if [ -z $1 ]; then
        ret="\033[1;31m*\033[1;37m"
    else
        ret="*"
    fi
  [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo -e $ret
}
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
function parse_git_branch {
  ref=$(git-symbolic-ref HEAD 2> /dev/null) || return
  echo " : "${ref#refs/heads/}"$(parse_git_dirty $1)"
}
function create_prompt {
    local BLUE="\[\033[0;34m\]"
    local RED="\[\033[0;31m\]"
    local LIGHT_RED="\[\033[1;31m\]"
    local GREEN="\[\033[0;32m\]"
    local LIGHT_GREEN="\[\033[1;32m\]"
    local WHITE="\[\033[1;37m\]"
    local LIGHT_GRAY="\[\033[0;37m\]"
 
    echo "$LIGHT_GRAY┌─($WHITE\u@\h$LIGHT_GRAY)\${fill}($WHITE\w\$(parse_git_branch)$LIGHT_GRAY)─┈"
    echo "└─(\$(date +%H:%M)) $LIGHT_GRAY$ "
}
export PS1=$(create_prompt)