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

My version with timeout, ahead/behind/staged/untracked markers and counts, and zsh support #32

Open
wants to merge 99 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
dc59f74
Show how many commits this branch is ahead/behind the remote
joeytwiddle Nov 16, 2014
326ee23
Use > and < instead of + and - to show ahead and behind count
joeytwiddle Nov 16, 2014
fa154c1
Do not mark dirty solely due to untracked files
joeytwiddle Nov 16, 2014
b214b01
Use square brackets instead of parentheses
joeytwiddle Nov 16, 2014
afe6413
Add colors to ahead/behind counts
joeytwiddle Nov 17, 2014
f8aaa15
Add $ at end of prompt, if branch is showing (assumes git_dirty is th…
joeytwiddle Nov 17, 2014
c76093e
Add a gap instead of $
joeytwiddle Nov 18, 2014
d7c7865
Instead of showing commit count, just show a minimalist marker
joeytwiddle Nov 18, 2014
d0c3a75
Separate ahead and behind markers and count, so they can be colored b…
joeytwiddle Nov 18, 2014
726c7e2
Empty the count strings when they are 0.
joeytwiddle Nov 18, 2014
2346e84
Empty the vars initially, in case we are not on a branch
joeytwiddle Nov 26, 2014
7d529f6
Do not check ahead/behind if we are on a detached branch (otherwise i…
joeytwiddle Nov 26, 2014
b55dfd2
Cleaner way to detech detached branch, and a comment.
joeytwiddle Nov 26, 2014
8d49a92
Code to show the hash (not enabled)
joeytwiddle Nov 26, 2014
084fdf0
Added ahead/behind marks and counts to the prompt documentation
joeytwiddle Dec 14, 2014
959ca80
Updated prompts for preprended space; fixed txtgreen->txtgrn
joeytwiddle Dec 17, 2014
a9c074c
Updated screenshot
joeytwiddle Dec 17, 2014
c23b150
Documented the unique features in this branch
joeytwiddle Dec 17, 2014
bde022d
FIX for bug when @{upstream} was not resolving
joeytwiddle Dec 18, 2014
f026c1a
Changed marks from -,+ to <,>
joeytwiddle Dec 19, 2014
fa7850a
Updated README with <,> and dirty count
joeytwiddle Dec 19, 2014
6b7d46f
Set prompt with no gap and updated preview pic and explanation
joeytwiddle Dec 19, 2014
5d19841
Fixed another txtgreen -> txtgrn
joeytwiddle Dec 19, 2014
9587fd9
Make markers bold, especially because red is dark on most terms
joeytwiddle Dec 19, 2014
29a89c1
Abort the check for git_dirty if it takes too long to complete.
joeytwiddle Dec 25, 2014
76a68e3
zsh compatibility
joeytwiddle Dec 25, 2014
c15f945
Notes
joeytwiddle Dec 28, 2014
a2c30e6
Fixed bug where wait was blocking on user-started jobs
joeytwiddle Dec 28, 2014
5218285
FIX The seq for sleep was broken, now fixed at ~1.5 seconds
joeytwiddle Dec 29, 2014
115ed80
Notes
joeytwiddle Dec 29, 2014
592dbd3
Small optimizations
joeytwiddle Dec 29, 2014
8b61c81
Since we are creating a subshell, we can just do unsetopt locally ins…
joeytwiddle Dec 29, 2014
87d50f0
Cleanup. Use variables for both temporary filenames, and separate th…
joeytwiddle Dec 29, 2014
c557cfe
Added git_staged_mark and git_staged_count
joeytwiddle Jan 3, 2015
76f9ff6
Dropped timeout to ~1 second
joeytwiddle Jan 3, 2015
82cd155
without timeout
joeytwiddle Jan 5, 2015
11d3b9d
Changed the staged marker from ~ to +
joeytwiddle Jan 8, 2015
383eb83
Added staged mark to the advanced prompts; also moved dirty mark to f…
joeytwiddle Jan 8, 2015
5821fe0
Simplification and style
joeytwiddle Jan 8, 2015
bab14c5
Modified code comments
joeytwiddle Jan 8, 2015
4689d37
Fixed typo
joeytwiddle Jan 8, 2015
7458f41
Documented new changes (staged count and timeout)
joeytwiddle Jan 8, 2015
7ceaf86
Consider newly added files in staged count
joeytwiddle Jan 15, 2015
5669294
Moved txtrst to end where it's needed, and set staged marker color to…
joeytwiddle Jan 15, 2015
0a3f91c
Indicates when top stash entry was made on current commit or branch
joeytwiddle Feb 8, 2015
385b519
Don't count staged files as dirty files
joeytwiddle Feb 12, 2015
71d93c6
Show short commit id when detached
joeytwiddle Feb 12, 2015
0ada914
FIX stash status should ignore current_branch when empty
joeytwiddle Feb 13, 2015
5d31d8c
Added optimization to find_git_ahead_branch
joeytwiddle Mar 1, 2015
87cf428
Consistent style
joeytwiddle Mar 1, 2015
369a6c5
Do not kill the `git status` process if the timeout is reached. Risks…
joeytwiddle Mar 7, 2015
cd0f871
Compatibility with git 1.7, and extra comments
joeytwiddle Jun 16, 2015
cdb0e3e
Remove the "done" file before processing (may mitigate a bug with emp…
joeytwiddle Jul 20, 2015
2d6b322
Count untracked files
joeytwiddle Jun 5, 2015
c8fb1cf
An alternative method for reading the branch of the top stash
joeytwiddle Jul 20, 2015
c5085f0
Updated README for stashed and untracked markers
joeytwiddle Jul 20, 2015
3135936
comments
joeytwiddle Aug 29, 2015
e54ca2a
List deleted files in the staged count too
joeytwiddle Aug 29, 2015
21fe00a
Do not inspect stash when inside .git folder; it was producing errors
joeytwiddle Oct 7, 2015
8b7411d
Count [R]enamed files in the staged files count
joeytwiddle Oct 11, 2015
ab9acc1
Count staged files using a blacklist not a whitelist
joeytwiddle Nov 5, 2015
b0a4c5a
comments
joeytwiddle Nov 5, 2015
bc67b81
If we are detached but current commit is tagged, show the tag.
joeytwiddle Nov 21, 2015
9d2cc0f
Linked to the git-prompt in oh-my-zsh
joeytwiddle Nov 21, 2015
a647f29
Noted odd display during rebase
joeytwiddle Dec 17, 2015
ce49254
Merge remote-tracking branch 'upstream/master'
joeytwiddle Dec 18, 2015
018c9e6
When getting tag, "undefined" is returned whenever we are detached
joeytwiddle Jan 4, 2016
6612da7
We should not count renames as dirty
joeytwiddle Mar 8, 2016
798a3a7
Count untracked files below untracked folders, not just the folders
joeytwiddle Mar 11, 2016
2607539
Do not count staged merge conflicts as dirty
joeytwiddle Apr 4, 2016
1c87a4b
Detect when we are in the middle of a merge, rebase or cherry-pick
joeytwiddle Apr 4, 2016
ebfe3fd
Merge remote-tracking branch 'upstream/master'
joeytwiddle Apr 4, 2016
fad1537
Explained in more detail why I unset MONITOR in a sub-shell
joeytwiddle Apr 4, 2016
3155e7d
Explained why using /usr/bin/timeout was a dead-end.
joeytwiddle Apr 4, 2016
7a22f51
Used {n..m} instead of `seq` (bash+zsh compatible); reduced the timeo…
joeytwiddle Apr 4, 2016
d42c8e3
Removed the spacer, since find_git_branch adds one when needed; also …
joeytwiddle Apr 4, 2016
03e1205
Added my extra marks to the suggested prompts
joeytwiddle Apr 4, 2016
659c4cb
Added zsh support
joeytwiddle Apr 4, 2016
f231958
Pinched detection of revert and bisect state from git-prompt.sh
joeytwiddle Apr 5, 2016
8c50cbc
Use brackets to indicate upstream/detached/working state
joeytwiddle Jun 29, 2016
8eb15ef
Slightly cleaner structure
joeytwiddle Jun 30, 2016
f2bffbe
Updated README for recent features
joeytwiddle Sep 2, 2016
c1f47ac
Update README.md with branch brackets meanings
joeytwiddle Jan 8, 2019
1291c72
Use dafeder's neater tag detection code
joeytwiddle Jun 23, 2019
6e0ca47
Note some other nice prompts
joeytwiddle Jun 23, 2019
f3e13a4
Use the '≡' symbol for stashes (suggested by carhartl)
joeytwiddle Jun 23, 2019
ef1e110
Display remote branch name if we are on a remote branch commit
joeytwiddle Mar 11, 2020
de5ca8f
Improve tag detection
joeytwiddle Oct 15, 2020
6c95164
Hide errors, if we are not in a git repo
joeytwiddle Oct 15, 2020
ba57015
Sometimes cherry-pick aborts with sequencer folder, but no CHERRY_PIC…
joeytwiddle Oct 15, 2020
11cdd43
Remove unnecessary error suppression
joeytwiddle Jul 1, 2021
968e18f
Use rev-list --count, but note that it could return ""
joeytwiddle Jul 1, 2021
7bbb549
Add zsh's vcs_info to README
joeytwiddle Aug 9, 2021
1472a46
Add prettier screenshot
joeytwiddle Aug 9, 2021
e18c126
Remove GITAWAREPROMPT usage
inshopper May 17, 2022
e898496
Prevent error on undefined PROMPT_COMMAND
inshopper Jul 27, 2022
560c3cb
Merge pull request #1 from Tony-Sol/master
joeytwiddle Oct 4, 2022
b8dbc21
Indicate more clearly the fork and its changes
joeytwiddle Mar 18, 2023
8f0be1e
Fix "stray \" error message from grep
joeytwiddle Mar 24, 2023
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
86 changes: 76 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Git Aware Prompt
# Git Aware Prompt (joeytwiddle's fork)

Working with Git and its great branching/merging features is
amazing. Constantly switching branches can be confusing though as you have to
run `git status` to see which branch you're currently on.

The solution to this is to have your terminal prompt display the current
branch. There's a [number][1] [of][2] [articles][3] [available][4] online
branch. There are a [number][1] [of][2] [articles][3] [available][4] online
about how to achieve this. This project is an attempt to make an easy to
install/configure solution.

Expand All @@ -21,7 +21,67 @@ 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)
.

**This fork by joeytwiddle also:**
- shows you how far your local branch is **ahead** or **behind** the repository's branch
- shows how many files are **staged**
- indicates when you have an un-popped **stash** (when the top stash entry was made on the current commit or the current branch)
- displays when you are on a **detached** commit, or paused during a merge, rebase or cherry-pick
- adds a **timeout** for slower machines so that you will get your prompt quickly, even if `git status` is taking too long to retrieve the dirty and staged stats. (Tested in bash and zsh.)

.

If you *only* want the ahead/behind marks (no timeout and no staged stats), you may prefer the branch [ahead_behind](https://github.com/joeytwiddle/git-aware-prompt/tree/ahead_behind) or if you are curious about the code, see [ahead_behind_simple](https://github.com/joeytwiddle/git-aware-prompt/tree/ahead_behind_simple) ([compare](https://github.com/joeytwiddle/git-aware-prompt/compare/jimeh:518685d5d42ab9f298207dd66bbc213775c5cbee...ahead_behind_simple?expand=1)).

The initial implementation of the timeout feature is on [this commit](https://github.com/joeytwiddle/git-aware-prompt/commit/29a89c1e6890689c819303ad33ef70ae4233589c).

![Git Branch in Prompt](https://github.com/joeytwiddle/git-aware-prompt/raw/master/preview.png)

> `≡` is a reminder that I have something on the stash.
>
> `<3` indicates that the local branch is 3 commits behind the upstream (remote) branch, and could/should be pulled.
>
> `?1` indicates that there is 1 untracked file in the tree.
>
> `+1` indicates that one file is staged for comitting.
>
> `>1` indicates that the local branch has 1 commit which has not yet been pushed to the upstream.
>
> `*1` indicates that the branch is dirty, with 1 file modified but not committed.
>
> `#` would indicate that `git status` has taken too long, so the markers are not shown.
>
> In that situation, `git status` will continue running in the background, so after a few moments, hitting `<Enter>` again should give you an up-to-date summary.

We also have some indicators for the current branch:

> `[branch_name]` means you are on a branch with an upstream
>
> `(branch_name)` means you are on a branch without an upstream
>
> `{branch_name\mode}` means you are in the middle of a merge, rebase, cherry-pick, revert or bisect
>
> `<commit_id>` means you are detached on the given commit, tag, or remote branch

The symbols (or "markers") can be changed by editing the `prompt.sh` file directly (and reloading it of course). The numbers or the markers can be omitted by removing the `_count` or `_mark` variables from the `PS1` prompt below.


## See Also

- The [original git-aware-prompt](https://github.com/jimeh/git-aware-prompt) by jimeh, from which this version is forked

- The [prompt now distributed with git](https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh) offers a `GIT_PS1_SHOWUPSTREAM` option.

- Zsh now ships with [vcs_info](https://git-scm.com/book/tr/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Zsh) which works for a variety of version control systems. (Unfortunately the docs for this are a big gnarly.)

- [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) has its own [git-prompt](https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/gitfast/git-prompt.sh). (It has 500 lines compared to our 200.)

- Inspiration for this fork came from [git-branch-status](https://gist.github.com/jehiah/1288596) by jehiah (a command, not a prompt)

- [pure](https://github.com/sindresorhus/pure) prompt by sindresorhus includes good git support (for zsh only)

- [liquidprompt](https://github.com/nojhan/liquidprompt) includes some git support (for bash and zsh)


## Installation
Expand All @@ -31,14 +91,13 @@ 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/joeytwiddle/git-aware-prompt.git
```

Edit your `~/.bash_profile` or `~/.profile` or `~/.bashrc` (for Ubuntu) and add the following to the top:

```bash
export GITAWAREPROMPT=~/.bash/git-aware-prompt
source "${GITAWAREPROMPT}/main.sh"
source "~/.bash/git-aware-prompt/main.sh"
```


Expand All @@ -65,14 +124,14 @@ end of the same file you pasted the installation code into earlier.
#### Mac OS X

```bash
export PS1="\u@\h \W \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "
export PS1="\u@\h \W\[$txtcyn\]\$git_branch\[$bldgrn\]\$git_ahead_mark\$git_ahead_count\[$txtrst\]\[$bldred\]\$git_behind_mark\$git_behind_count\[$txtrst\]\[$bldylw\]\$git_stash_mark\[$txtrst\]\[$txtylw\]\$git_dirty\$git_dirty_count\[$txtrst\]\[$txtcyn\]\$git_staged_mark\$git_staged_count\[$txtrst\]\[$txtblu\]\$git_unknown_mark\$git_unknown_count\[$txtrst\]\$ "
```

Optionally, if you want a nice pretty prompt when using `sudo -s`, also add
this line:

```bash
export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\] \w\$ "
export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\]\w\$ "
```


Expand All @@ -81,13 +140,20 @@ export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\] \w\$ "
Standard:

```bash
export PS1="\${debian_chroot:+(\$debian_chroot)}\u@\h:\w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "
export PS1="\${debian_chroot:+(\$debian_chroot)}\u@\h:\w\[$txtcyn\]\$git_branch\[$bldgrn\]\$git_ahead_mark\$git_ahead_count\[$txtrst\]\[$bldred\]\$git_behind_mark\$git_behind_count\[$txtrst\]\[$bldyellow\]\$git_stash_mark\[$txtrst\]\[$txtylw\]\$git_dirty\$git_dirty_count\[$txtrst\]\[$txtcyn\]\$git_staged_mark\$git_staged_count\[$txtrst\]\[$txtblu\]\$git_unknown_mark\$git_unknown_count\[$txtrst\]\$ "
```

Colorized:

```bash
export PS1="\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "
export PS1="\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[$txtcyn\]\$git_branch\[$bldgrn\]\$git_ahead_mark\$git_ahead_count\[$txtrst\]\[$bldred\]\$git_behind_mark\$git_behind_count\[$txtrst\]\[$bldyellow\]\$git_stash_mark\[$txtrst\]\[$txtylw\]\$git_dirty\$git_dirty_count\[$txtrst\]\[$txtcyn\]\$git_staged_mark\$git_staged_count\[$txtrst\]\[$txtblu\]\$git_unknown_mark\$git_unknown_count\[$txtrst\]\$ "
```


#### ZSH

```zsh
export PROMPT='%n@%m:%~%{$bldpur%}$git_branch%{$bldgrn%}$git_ahead_mark$git_ahead_count%{$bldred%}$git_behind_mark$git_behind_count%{$bldylw%}$git_stash_mark%{$txtrst$txtylw%}$git_dirty$git_dirty_count%{$txtcyn%}$git_staged_mark$git_staged_count%{$txtblu%}$git_unknown_mark$git_unknown_count%{$txtrst%}$ '
```


Expand Down
4 changes: 2 additions & 2 deletions main.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source "${GITAWAREPROMPT}/colors.sh"
source "${GITAWAREPROMPT}/prompt.sh"
source "$(dirname $0)/colors.sh"
source "$(dirname $0)/prompt.sh"
Binary file modified preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading