3 _cgmem_which="`cgmem_which 2>/dev/null`"
4 if [ -n "$_cgmem_which" ]; then
5 _cgmem_which=" $_cgmem_which"
10 # Cut directories to 20% of the terminal width; add space for 3 dots
11 _DIR_LENGTH=`awk "END { print int(0.2 * ${COLUMNS:-80}) }" </dev/null`
12 _DIR_LENGTH_DOTS=`expr $_DIR_LENGTH + 3`
15 if [ "$PWD" = / ]; then
19 if [ "$PWD" = "$HOME" ]; then
24 _short_curdir="${PWD##*/}" # cut all directories, get base name
25 if [ "${#_short_curdir}" -gt $_DIR_LENGTH_DOTS ]; then
26 _short_curdir="${_short_curdir::$_DIR_LENGTH}..." # cut long string
28 echo "${_short_curdir}"
31 # bash_prompt; adapted from
32 # https://github.com/necolas/dotfiles/blob/master/shell/bash_prompt and
33 # https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
39 # check if the current directory is in a git repository
40 if git rev-parse --is-inside-work-tree &>/dev/null; then
42 # check if the current directory is in .git before running git checks
43 if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == "false" ]; then
45 # ensure index is up to date
46 #git update-index --really-refresh -q &>/dev/null
48 # check for unstaged changes
49 if [ -n "$(git ls-files --modified)" ]; then
53 # check for uncommitted changes in the index
54 if ! $(git diff --quiet --ignore-submodules --cached); then
58 # check for stashed files
59 if $(git rev-parse --verify refs/stash &>/dev/null); then
63 # check for untracked files
64 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
70 # get the short symbolic ref
71 # if HEAD isn't a symbolic ref, get the short SHA
72 # otherwise, just give up
73 branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
74 git rev-parse --short HEAD 2> /dev/null || \
77 up=`git rev-parse --abbrev-ref @{u} 2>/dev/null`
78 if [ -n "$up" -a "$up" != "@{u}" ]; then
80 set -- `git rev-list --count --left-right @{u}...HEAD`
83 if [ "$left" -gt 0 ]; then
86 if [ "$right" -gt 0 ]; then
91 [ -n "$s" ] && s=" $s"
92 printf " (%s)" "$branchName$s"
96 #if test -x /usr/bin/git >/dev/null 2>&1; then
97 # if [ "`type -t __git_ps1`" != function ]; then
98 # git_sh_prompt=`git --exec-path`/git-sh-prompt
99 # test -r $git_sh_prompt && . $git_sh_prompt || :
101 # if [ "`type -t __git_ps1`" = function ]; then
102 # GIT_PS1_SHOWDIRTYSTATE=true
103 # GIT_PS1_SHOWSTASHSTATE=true
104 # GIT_PS1_SHOWUNTRACKEDFILES=true
105 # GIT_PS1_SHOWUPSTREAM=verbose
111 local _COMMON_PROMPT='${debian_chroot:+($debian_chroot)}\u@\h:\w'
112 # display the user, host and current working directory
113 # in the terminal title
115 *rxvt*|screen*|*term*|vt100)
116 PS1="\033]0;${_COMMON_PROMPT}\007" # Set xterm title/icon
119 PS1="\033P${PS1}\033\\\\" # Set xterm title/icon under screen/tmux
120 if [ -z "$MC_SID" ]; then
121 PS1+="\033k${_COMMON_PROMPT}\033\\\\" # Set screen/tmux caption
132 # This is for .screenrc: shelltitle "\$ |$SHELL"
136 PS1+='${debian_chroot:+($debian_chroot)}'
137 PS1+='[\A`cgmem_which_prompt`] \u@${HOSTNAME::5}:`short_curdir`'
138 if test -x /usr/bin/git >/dev/null 2>&1; then
139 #if [ "`type -t __git_ps1`" = function ]; then
140 # PS1+='$(__git_ps1)'