Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions prompt.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
find_git_branch() {
# Based on: http://stackoverflow.com/a/13003854/170413
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached*'
if [ x$DISABLE_GIT_AWARE = x ]; then
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached*'
fi
git_branch="($branch)"
else
git_branch=""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to git_branch="(git check disabled)" or something similar in case the user was wondering why it didn't work.

fi
git_branch="($branch)"
else
git_branch=""
fi
fi
}

find_git_dirty() {
local status=$(git status --porcelain 2> /dev/null)
if [[ "$status" != "" ]]; then
git_dirty='*'
if [ x$DISABLE_GIT_AWARE = x ]; then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this function to always set git_dirty='' at the beginning and then add [ -z "${DISABLE_GIT_AWARE}" ] || return to guard instead of needing to indent everything beyond it.

local status=$(git status --porcelain 2> /dev/null)
if [[ "$status" != "" ]]; then
git_dirty='*'
else
git_dirty=''
fi
else
git_dirty=''
fi
fi
}

PROMPT_COMMAND="find_git_branch; find_git_dirty; $PROMPT_COMMAND"
Expand Down