PageRenderTime 20ms CodeModel.GetById 1ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/.bash_prompt

https://github.com/Ephemera/dotfiles
#! | 71 lines | 65 code | 6 blank | 0 comment | 0 complexity | 97222c587b2b1b7892c6ba4b0d574bc9 MD5 | raw file
 1# Fork from https://github.com/gf3/dotfiles/blob/master/.bash_prompt
 2# Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt"
 3# Screenshot: http://img.gf3.ca/d54942f474256ec26a49893681c49b5a.png
 4# A big thanks to \amethyst on Freenode
 5
 6if [[ $COLORTERM = gnome-* && $TERM = xterm ]]  && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color
 7elif infocmp xterm-256color >/dev/null 2>&1; then export TERM=xterm-256color
 8fi
 9
10if tput setaf 1 &> /dev/null; then
11    tput sgr0
12    if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
13      MAGENTA=$(tput setaf 9)
14      ORANGE=$(tput setaf 172)
15      GREEN=$(tput setaf 190)
16      PURPLE=$(tput setaf 141)
17      WHITE=$(tput setaf 256)
18	  #WHITE=$(tput setaf 0)
19      CYAN=$(tput setaf 6)
20    else
21      MAGENTA=$(tput setaf 5)
22      ORANGE=$(tput setaf 4)
23      GREEN=$(tput setaf 2)
24      PURPLE=$(tput setaf 1)
25      WHITE=$(tput setaf 7)
26      CYAN=$(tput setaf 6)
27    fi
28    BOLD=$(tput bold)
29    RESET=$(tput sgr0)
30else
31    MAGENTA="\033[1;31m"
32    ORANGE="\033[1;33m"
33    GREEN="\033[1;32m"
34    PURPLE="\033[1;35m"
35    WHITE="\033[1;37m"
36	CYAN="\033[1;36m"
37    BOLD=""
38    RESET="\033[m"
39fi
40
41parse_git_dirty () {
42  [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
43}
44parse_git_branch () {
45  git branch -v --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \([^ ]*\)\ *\([^ ]*\) \(.*\)/\1:\2$(parse_git_dirty)/"
46}
47parse_git_just_branch () {
48  git branch --contains 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1:$(parse_git_hash)$(parse_git_dirty)/"
49}
50parse_git_hash() {
51  git rev-parse --short HEAD 2> /dev/null
52}
53parse_git_hash1 () {
54  ((git log --pretty=format:'%h' -n 1)) && git log --pretty=format:'%h' -n 1
55}
56
57parse_hg_dirty () {
58  [[ $(hg status 2> /dev/null | head -n1 | cut -c 1) == "M" ]] && echo "*" 
59}
60parse_hg_branch () {
61  hg branch 2> /dev/null | sed -e "s/\(.*\)/\1$(parse_hg_dirty)/"
62}
63
64jobscount() {
65  local stopped=$(jobs -sp | wc -l)
66  local running=$(jobs -rp | wc -l)
67  ((running+stopped)) && echo "${running}r/${stopped}s"
68}
69
70#PS1="\[${PURPLE}\]\u \[$WHITE\]at \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\$([[ -n \$(hg branch 2> /dev/null) ]] && echo \" on \")\[$CYAN\]\$(parse_hg_branch)\[$WHITE\]\n\#> \[$RESET\]"
71PS1="\n\$([ \j -gt 0 ] && echo [\j]\ )\u@\h:\w\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" - \")\$(parse_git_just_branch)\n\#> "