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
46 _recurse_submodules() {
48 local output="$($command 2>/dev/null)"
49 if [ -n "$output" ]; then
53 git submodule --quiet foreach $command 2>/dev/null
60 # check if the current directory is in a git repository
61 if git rev-parse --is-inside-work-tree &>/dev/null; then
63 # check if the current directory is in .git before running git checks
64 if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == "false" ]; then
66 # ensure index is up to date
67 #git update-index --really-refresh -q &>/dev/null
69 # check for unstaged changes
70 if [ -n "$(_recurse_submodules git ls-files --modified :/)" ]; then
74 # check for uncommitted changes in the index
75 if [ -n "$(_recurse_submodules git diff --ignore-submodules --cached)" ]; then
79 # check for stashed files
80 if [ -n "$(_recurse_submodules git rev-parse --verify refs/stash)" ]; then
84 # check for untracked files
85 if [ -n "$(_recurse_submodules git ls-files --others --exclude-standard :/)" ]; then
91 # get the short symbolic ref
92 # if HEAD isn't a symbolic ref, get the short SHA
93 # otherwise, just give up
94 branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
95 git rev-parse --short HEAD 2> /dev/null || \
98 up=`git rev-parse --abbrev-ref @{u} 2>/dev/null`
99 if [ -n "$up" -a "$up" != "@{u}" ]; then
101 set -- `git rev-list --count --left-right @{u}...HEAD`
104 if [ "$left" -gt 0 ]; then
107 if [ "$right" -gt 0 ]; then
112 [ -n "$s" ] && s=" $s"
113 printf " (%s)" "$branchName$s"
117 #if test -x /usr/bin/git >/dev/null 2>&1; then
118 # if [ "`type -t __git_ps1`" != function ]; then
119 # git_sh_prompt=`git --exec-path`/git-sh-prompt
120 # test -r $git_sh_prompt && . $git_sh_prompt || :
122 # if [ "`type -t __git_ps1`" = function ]; then
123 # GIT_PS1_SHOWDIRTYSTATE=true
124 # GIT_PS1_SHOWSTASHSTATE=true
125 # GIT_PS1_SHOWUNTRACKEDFILES=true
126 # GIT_PS1_SHOWUPSTREAM=verbose
132 local _SHORT_PROMPT='[\A`cgmem_which_prompt`] \u@${HOSTNAME::5}:`short_curdir`'
133 # display the user, host and current working directory
134 # in the terminal title
136 *rxvt*|screen*|*term*|vt100)
137 PS1+="\033]0;${debian_chroot:+($debian_chroot)}\u@\h:\w\007" # Set xterm title/icon
140 PS1+="\033P${PS1}\033\\\\" # Set xterm title/icon under screen/tmux
141 if [ -z "$MC_SID" ]; then
142 PS1+="\033k${_SHORT_PROMPT}\033\\\\" # Set screen/tmux caption
149 # This is for .screenrc: shelltitle "\$ |$SHELL"
153 PS1+='${debian_chroot:+($debian_chroot)}'
154 PS1+=${_SHORT_PROMPT}
155 if test -x /usr/bin/git >/dev/null 2>&1; then
156 #if [ "`type -t __git_ps1`" = function ]; then
157 # PS1+='$(__git_ps1)'