Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed detached head branch to be commit id and tags #41

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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]
Expand Down Expand Up @@ -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/)
13 changes: 11 additions & 2 deletions prompt.sh
Original file line number Diff line number Diff line change
@@ -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=""
Expand Down