3 _cgmem_which="`cgmem_which 2>/dev/null`"
4 if [ -n "$_cgmem_which" ]; then
5 _cgmem_which=" $_cgmem_which"
12 if [ $_last_status -eq 0 ]; then
14 elif [ $_last_status -ge 1 ]; then
21 # Cut directories to 20% of the terminal width; add space for 3 dots
22 _DIR_LENGTH=`awk "END { print int(0.2 * ${COLUMNS:-80}) }" </dev/null`
23 _DIR_LENGTH_DOTS=`expr $_DIR_LENGTH + 3`
26 if [ "$PWD" = / ]; then
30 if [ "$PWD" = "$HOME" ]; then
35 _short_curdir="${PWD##*/}" # cut all directories, get base name
36 if [ "${#_short_curdir}" -gt $_DIR_LENGTH_DOTS ]; then
37 _short_curdir="${_short_curdir::$_DIR_LENGTH}..." # cut long string
39 echo "${_short_curdir}"
42 # bash_prompt; adapted from
43 # https://github.com/necolas/dotfiles/blob/master/shell/bash_prompt and
44 # https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
50 # check if the current directory is in a git repository
51 if git rev-parse --is-inside-work-tree &>/dev/null; then
53 # check if the current directory is in .git before running git checks
54 if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == "false" ]; then
56 # ensure index is up to date
57 #git update-index --really-refresh -q &>/dev/null
59 # check for unstaged changes
60 if [ -n "$(git ls-files --modified :/)" ]; then
64 # check for uncommitted changes in the index
65 if ! $(git diff --quiet --ignore-submodules --cached); then
69 # check for stashed files
70 if $(git rev-parse --verify refs/stash &>/dev/null); then
74 # check for untracked files
75 if [ -n "$(git ls-files --others --exclude-standard :/)" ]; then
81 # get the short symbolic ref
82 # if HEAD isn't a symbolic ref, get the short SHA
83 # otherwise, just give up
84 branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
85 git rev-parse --short HEAD 2> /dev/null || \
88 up=`git rev-parse --abbrev-ref @{u} 2>/dev/null`
89 if [ -n "$up" -a "$up" != "@{u}" ]; then
91 set -- `git rev-list --count --left-right @{u}...HEAD`
94 if [ "$left" -gt 0 ]; then
97 if [ "$right" -gt 0 ]; then
102 [ -n "$s" ] && s=" $s"
103 printf " (%s)" "$branchName$s"
107 #if test -x /usr/bin/git >/dev/null 2>&1; then
108 # if [ "`type -t __git_ps1`" != function ]; then
109 # git_sh_prompt=`git --exec-path`/git-sh-prompt
110 # test -r $git_sh_prompt && . $git_sh_prompt || :
112 # if [ "`type -t __git_ps1`" = function ]; then
113 # GIT_PS1_SHOWDIRTYSTATE=true
114 # GIT_PS1_SHOWSTASHSTATE=true
115 # GIT_PS1_SHOWUNTRACKEDFILES=true
116 # GIT_PS1_SHOWUPSTREAM=verbose
122 local _SHORT_PROMPT='[\A`cgmem_which_prompt`] \u@${HOSTNAME::5}:`short_curdir`'
123 # display the user, host and current working directory
124 # in the terminal title
126 *rxvt*|screen*|*term*|vt100)
127 PS1+="\033]0;${debian_chroot:+($debian_chroot)}\u@\h:\w\007" # Set xterm title/icon
130 PS1+="\033P${PS1}\033\\\\" # Set xterm title/icon under screen/tmux
131 if [ -z "$MC_SID" ]; then
132 PS1+="\033k${_SHORT_PROMPT}\033\\\\" # Set screen/tmux caption
139 # This is for .screenrc: shelltitle "\$ |$SHELL"
143 PS1+='${debian_chroot:+($debian_chroot)}'
144 PS1+=${_SHORT_PROMPT}
145 if test -x /usr/bin/git >/dev/null 2>&1; then
146 #if [ "`type -t __git_ps1`" = function ]; then
147 # PS1+='$(__git_ps1)'