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