|
| 1 | +# -*- coding: utf-8 ; mode: sh -*- |
| 2 | +# |
| 3 | +# bash-prompt.sh |
| 4 | +# -------------- |
| 5 | +# Source me for a git-enabled, utf-8, coloured bash prompt and extra functions |
| 6 | +# 'shorten' and 'lengthen' for showing the full path or the rightmost |
| 7 | +# directory name for the current working directory. |
| 8 | +# |
| 9 | +# Be sure to source the git-prompt.sh script first! |
| 10 | +# |
| 11 | +# :authors: Isis Agora Lovecruft 0xa3adb67a2cdb8b35 |
| 12 | +# :version: 0.1.0 |
| 13 | +# :license: WTFPL |
| 14 | +# |
| 15 | + |
| 16 | +## uncomment for a colored prompt |
| 17 | +force_color_prompt=yes |
| 18 | +if [ -n "$force_color_prompt" ]; then |
| 19 | + if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then |
| 20 | + ## We have color support; assume it's compliant with Ecma-48 |
| 21 | + ## (ISO/IEC-6429). (Lack of such support is extremely rare, and such |
| 22 | + ## a case would tend to support setf rather than setaf.) |
| 23 | + color_prompt=yes |
| 24 | + else |
| 25 | + color_prompt=no |
| 26 | + fi |
| 27 | +fi |
| 28 | + |
| 29 | +## Allow git repos to be discovered on other filesystems: |
| 30 | +GIT_DISCOVERY_ACROSS_FILESYSTEM=true |
| 31 | +export GIT_DISCOVERY_ACROSS_FILESYSTEMS |
| 32 | + |
| 33 | +## If you set GIT_PS1_SHOWDIRTYSTATE to a nonempty |
| 34 | +## value, unstaged (*) and staged (+) changes will be shown next |
| 35 | +## to the branch name. You can configure this per-repository |
| 36 | +## with the bash.showDirtyState variable, which defaults to true |
| 37 | +## once GIT_PS1_SHOWDIRTYSTATE is enabled. |
| 38 | +GIT_PS1_SHOWDIRTYSTATE=true |
| 39 | + |
| 40 | +## You can also see if currently something is stashed, by setting |
| 41 | +## GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed, |
| 42 | +## then a '$' will be shown next to the branch name. |
| 43 | +GIT_PS1_SHOWSTASHSTATE=true |
| 44 | + |
| 45 | +## If you would like to see if there're untracked files, then you can |
| 46 | +## set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're |
| 47 | +## untracked files, then a '%' will be shown next to the branch name. |
| 48 | +## |
| 49 | +#GIT_PS1_SHOWUNTRACKEDFILES=true |
| 50 | + |
| 51 | +## If you would like to see the difference between HEAD and its |
| 52 | +## upstream, set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates |
| 53 | +## you are behind, ">" indicates you are ahead, and "<>" |
| 54 | +## indicates you have diverged. You can further control |
| 55 | +## behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated |
| 56 | +## list of values: |
| 57 | +## verbose show number of commits ahead/behind (+/-) upstream |
| 58 | +## legacy don't use the '--count' option available in recent |
| 59 | +## versions of git-rev-list |
| 60 | +## git always compare HEAD to @{upstream} |
| 61 | +## svn always compare HEAD to your SVN upstream |
| 62 | +## auto just the '<', '>', or '<>' |
| 63 | +## By default, __git_ps1 will compare HEAD to your SVN upstream |
| 64 | +## if it can find one, or @{upstream} otherwise. Once you have |
| 65 | +## set GIT_PS1_SHOWUPSTREAM, you can override it on a |
| 66 | +## per-repository basis by setting the bash.showUpstream config |
| 67 | +## variable. |
| 68 | +GIT_PS1_SHOWUPSTREAM="auto" |
| 69 | +#GIT_PS1_SHOWUPSTREAM="verbose" |
| 70 | + |
| 71 | +if [ "$color_prompt" = yes ]; then |
| 72 | + if [ $(id -u) != "0" ]; then |
| 73 | + PROMPT_COMMAND='prmcmd=`__git_ps1 "(%s)"`' |
| 74 | + PS1='\[\033[0m\033[32m\]∃!\[\033[33m\]\u\[\033[32m\]Ⓐ\[\033[36m\]\h\[\033[32m\]:\[\033[33m\]$prmcmd\w\[\033[32m\] ∴ \[\033[0m' |
| 75 | + else |
| 76 | + ## If root make the prompt red so that we notice we're in a root shell |
| 77 | + PROMPT_COMMAND='prmcmd=`__git_ps1 "(%s)"`' |
| 78 | + PS1='\[\033[0m\033[32m\]∃!\[\033[33m\]\u\[\033[32m\]Ⓐ\[\033[36m\]\h\[\033[32m\]:\[\033[33m\]$prmcmd\w\[\033[31m\] ∴ \[\033[0m' |
| 79 | + fi |
| 80 | +else |
| 81 | + PS1='\[\u@\h:\w\]\$ ' |
| 82 | +fi |
| 83 | + |
| 84 | +## load the longer prompt |
| 85 | +function lengthen () { |
| 86 | + if [ $(id -u) != "0" ]; then |
| 87 | + PROMPT_COMMAND='prmcmd=`__git_ps1 "(%s)"`' |
| 88 | + PS1='\[\033[0m\033[32m\]∃!\[\033[33m\]\u\[\033[32m\]Ⓐ\[\033[36m\]\h\[\033[32m\]:\[\033[33m\]$prmcmd\w\[\033[32m\] ∴ \[\033[0m' |
| 89 | + else |
| 90 | + PROMPT_COMMAND='prmcmd=`__git_ps1 "(%s)"`' |
| 91 | + PS1='\[\033[0m\033[32m\]∃!\[\033[33m\]\u\[\033[32m\]Ⓐ\[\033[36m\]\h\[\033[32m\]:\[\033[33m\]$prmcmd\w\[\033[31m\] ∴ \[\033[0m' |
| 92 | + fi |
| 93 | +} |
| 94 | + |
| 95 | +function shorten () { |
| 96 | + if [ $(id -u) != "0" ]; then |
| 97 | + PROMPT_COMMAND='prmcmd=`__git_ps1 "(%s)"`' |
| 98 | + PS1='\[\033[0m\033[32m\]∃!\[\033[33m\]\u\[\033[32m\]Ⓐ\[\033[36m\]\h\[\033[32m\]:\[\033[33m\]$prmcmd\W\[\033[32m\] ∴ \[\033[0m' |
| 99 | + else |
| 100 | + PROMPT_COMMAND='prmcmd=`__git_ps1 "(%s)"`' |
| 101 | + PS1='\[\033[0m\033[32m\]∃!\[\033[33m\]\u\[\033[32m\]Ⓐ\[\033[36m\]\h\[\033[32m\]:\[\033[33m\]$prmcmd\W\[\033[31m\] ∴ \[\033[0m' |
| 102 | + fi |
| 103 | +} |
| 104 | + |
| 105 | +PS2='… ' |
| 106 | +PS3='… ' |
| 107 | +PS4='… ' |
| 108 | +unset color_prompt force_color_prompt |
0 commit comments