diff --git a/README.md b/README.md index ffaadcc..eee0427 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +Forked from: https://github.com/jimeh/git-aware-prompt + # Git Aware Prompt Working with Git and its great branching/merging features is @@ -21,7 +23,7 @@ If you `cd` to a Git working directory, you will see the current Git branch name displayed in your terminal prompt. When you're not in a Git working directory, your prompt works like normal. -![Git Branch in Prompt](https://raw.github.com/jimeh/git-aware-prompt/master/preview.png) +![Git Branch in Prompt](https://github.com/H2oBoi89-Forks/git-aware-prompt/blob/master/preview.png) ## Installation @@ -31,7 +33,7 @@ Clone the project to a `.bash` folder in your home directory: ```bash mkdir ~/.bash cd ~/.bash -git clone git://github.com/jimeh/git-aware-prompt.git +git clone git@github.com:H2oBoi89-Forks/git-aware-prompt.git ``` Edit your `~/.bash_profile` or `~/.profile` or `~/.bashrc` (for Ubuntu) and add the following to the top: @@ -48,7 +50,7 @@ Once installed, there will be new `$git_branch` and `$git_dirty` variables available to use in the `PS1` environment variable, along with a number of color helper variables which you can see a list of in [colors.sh][]. -[colors.sh]: https://github.com/jimeh/git-aware-prompt/blob/master/colors.sh +[colors.sh]: https://github.com/H2oBoi89/git-aware-prompt/blob/master/colors.sh If you want to know more about how to customize your prompt, I recommend this article: [How to: Change / Setup bash custom prompt (PS1)][how-to] @@ -106,14 +108,6 @@ cd ~/.bash/git-aware-prompt git pull ``` - -## Usage Tips - -To view other user's tips, please check the -[Usage Tips](https://github.com/jimeh/git-aware-prompt/wiki/Usage-Tips) wiki -page. Or if you have tips of your own, feel free to add them :) - - ## License [CC0 1.0 Universal](http://creativecommons.org/publicdomain/zero/1.0/) diff --git a/prompt.sh b/prompt.sh index 6a737b8..9d38d06 100644 --- a/prompt.sh +++ b/prompt.sh @@ -1,10 +1,19 @@ 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*' + local tag + + tag=$(git name-rev --tags --name-only $(git rev-parse HEAD)) + + if [[ $tag == *"~"* || $tag == *" "* || $tag == *"undefined"* ]]; then + branch=$(git log -1 --format="%h" 2> /dev/null) + else + branch="tags/$tag" + fi fi + git_branch="($branch)" else git_branch=""