Skip to content
Open
Changes from 1 commit
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,27 +1,35 @@
is_this_a_git_repo() {
is_in_git=$(git rev-parse --is-inside-work-tree 2> /dev/null)
}

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*'
echo $is_in_git

Choose a reason for hiding this comment

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

Is this leftover debug code?

Copy link
Author

Choose a reason for hiding this comment

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

Ah yeah it is. Wow I've been running it myself but didn't notice. Guess I forgot to commit the removal. Will do tomorrow

Copy link
Author

Choose a reason for hiding this comment

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

Oh forgot to message, I removed the debugging already

if [[ "$is_in_git" = "true" ]]; then
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached*'
fi
git_branch="($branch)"
fi
git_branch="($branch)"
else
git_branch=""
fi
}

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

find_head_tag() {
local is_in_git=$(git rev-parse --is-inside-work-tree 2> /dev/null)
if [[ "$is_in_git" = "true" ]]; then
local tag=$(git tag --column --points-at HEAD 2> /dev/null)
if [[ ! -z $tag ]]; then
Expand All @@ -34,7 +42,7 @@ find_head_tag() {
fi
}

PROMPT_COMMAND="find_git_branch; find_git_dirty; find_head_tag; $PROMPT_COMMAND"
PROMPT_COMMAND="is_this_a_git_repo; find_git_branch; find_git_dirty; find_head_tag;$PROMPT_COMMAND"

# Default Git enabled prompt with dirty state
# export PS1="\u@\h \w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "
Expand Down