Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e62452b
README: remove spaces that increase horisontal scroll
vitaly-zdanevich Jul 26, 2022
4b22821
Merge pull request #498 from vitaly-zdanevich/patch-1
guenhter Oct 10, 2022
d015835
Use --no-optional-locks in gitstatus.sh to speed up prompt in large r…
Jan 6, 2022
0eb0947
Fixes for Solarized_UserHost.
rkitover Dec 30, 2021
14bf43a
Add new theme: Windows_UserHost.
rkitover Dec 30, 2021
955c90f
Export variables for changing output
me-and Dec 29, 2021
034b2b1
Removed duplicate _LAST_COMMAND_INDICATOR_
LordMailman Mar 12, 2021
5da0a40
Replace while read loop with a readarray
andyjack Feb 9, 2021
57ac5ba
Add HOME environment variable to git status call
jcjf Jun 28, 2020
d505212
Update rpm spec.
hramrach Feb 20, 2020
1f32665
Allow to coexist other PROMPT_COMMAND(s) relying on command exit status
mskalski Nov 29, 2019
c9b5c73
Cleanup the readme
Oct 14, 2022
352aaf0
Revert "Replace while read loop with a readarray"
guenhter Oct 14, 2022
a8e4ffa
Added GIT_PROMPT_SHOW_TRACKING flag to options
jaketesler Jul 17, 2019
6d10abf
Update var check for consistency
jaketesler Oct 14, 2022
8241a18
Support running bash tests
Oct 17, 2022
21fcf1c
Refactor PROMPT_COMMAND setup
Oct 17, 2022
5184a89
Enhance git_prompt_help and example with real colors and markers
mskalski Nov 29, 2019
7cd46d9
git-help-examples-fixup: Some more minor tweaks in help and examples
mskalski Dec 19, 2019
4d02d6b
Make the old prompt handling slighlty easier
Oct 18, 2022
0e18945
Make getting the git prompt dir easier
Oct 18, 2022
e433e46
Update Default.bgptheme
aharonha Jul 31, 2019
82a1fd5
Minimal chevron theme reload patch
Apr 8, 2019
af82e91
Make venv position configurable.
bibermann Nov 28, 2019
feb7f35
Honour TMPDIR variable for cases when /tmp dir does not exist (i.e. o…
mskalski Oct 16, 2022
6dbba24
Fixes git state 'D' was wrongly identified as 'stashed'.
mskalski Oct 16, 2022
0101261
README: add block with similar projects
vitaly-zdanevich Oct 24, 2022
a9fd391
Multi Line Theme for Gentoo Default Prompt without Exit State
NorbertRonecker Oct 14, 2022
cd2326d
Add new theme BlackOrWhite
norbertszivos Feb 29, 2020
31e5a41
Add Nerd Fonts to BlackOrWhite theme
norbertszivos Dec 14, 2020
31c47f7
Improve BlackOrWhite.bgptheme
norbertszivos Oct 16, 2022
b2deaa5
Add custom themes
jenciso Sep 4, 2022
c9d0181
Add GIT_PROMPT_SYMBOLS_PRETAG
baincd Jan 23, 2018
cada5cb
Add GIT_PROMPT_DETACHED_HEAD
baincd Jan 23, 2018
7fb605e
Add support for zsh
geksiong Apr 19, 2020
18103a0
Fix 'can't manipulate jobs in subshell' error in zsh
geksiong May 8, 2020
04a9901
Correct issues with default theme on zsh
MPLew-is May 18, 2020
9abaa39
Quote use of `$ZSH_VERSION`
MPLew-is Dec 1, 2020
8300c6e
Fix bash compatibility
MPLew-is Dec 1, 2020
212b9db
Restore upstream `set_git_prompt_dir`
MPLew-is Feb 21, 2023
8695c70
Fix improper use of `==` with `[`
MPLew-is Feb 21, 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
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.sh]
indent_size = 2
73 changes: 23 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,8 @@ A ``bash`` prompt that displays information about the current git repository.
In particular the branch name, difference with remote branch, number of files
staged, changed, etc.

(an original idea from this [blog post][]).

`gitstatus.sh` and `git-prompt-help.sh` added by [AKS](http://github.com/aks).

# ATTENTION! Breaking changes!

**If you use this prompt already, please update your `.git-prompt-colors.sh`,
if you have one. It now contains a function named `define_git_prompt_colors()` or `override_git_prompt_colors()`!**

**Please see the ``Custom.bgptemplate`` in the ``themes`` subdirectory of the installation directory!**

**You can now also use the function `override_git_prompt_colors()`. It should define the variable `GIT_PROMPT_THEME_NAME`
and call the function `reload_git_prompt_colors <ThemeName>` like follows:**

```sh
override_git_prompt_colors() {
GIT_PROMPT_THEME_NAME="Custom" # needed for reload optimization, should be unique

# Place your overrides here
...
}

# load the theme
reload_git_prompt_colors "Custom"
```

The advantage of this approach is, that you only need to specify the parts, that are different to the Default theme.

---

**The variable `GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR` was replaced with a more general placeholder
named ``_LAST_COMMAND_INDICATOR_``, which is replaced by the state of the last executed command. It is now activated by default.**

## Examples

The prompt may look like the following:
Expand Down Expand Up @@ -75,7 +44,7 @@ The symbols are as follows:
- Upstream branch
- Shows the remote tracking branch
- Disabled by default
- Enable by setting GIT_PROMPT_SHOW_UPSTREAM=1
- Enable by setting `GIT_PROMPT_SHOW_UPSTREAM=1`
- Branch Tracking Symbols
- ``↑n``: ahead of remote by ``n`` commits
- ``↓n``: behind remote by ``n`` commits
Expand Down Expand Up @@ -121,7 +90,7 @@ fi

### install for the fish shell

- If you cloned the repo to a directory other then ~/.bash-git-prompt , set __GIT_PROMPT_DIR in ~/.config/fish/config.fish
- If you cloned the repo to a directory other then `~/.bash-git-prompt` , set `__GIT_PROMPT_DIR` in `~/.config/fish/config.fish`
to that path

- To install as an option in the fish_config GUI
Expand All @@ -146,28 +115,29 @@ cp gitprompt.fish ~/.config/fish/functions/fish_prompt.fish

```sh

# Set config variables first
GIT_PROMPT_ONLY_IN_REPO=1
# Set config variables first
GIT_PROMPT_ONLY_IN_REPO=1

# GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status
# GIT_PROMPT_IGNORE_SUBMODULES=1 # uncomment to avoid searching for changed files in submodules
# GIT_PROMPT_WITH_VIRTUAL_ENV=0 # uncomment to avoid setting virtual environment infos for node/python/conda environments
# GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status
# GIT_PROMPT_IGNORE_SUBMODULES=1 # uncomment to avoid searching for changed files in submodules
# GIT_PROMPT_WITH_VIRTUAL_ENV=0 # uncomment to avoid setting virtual environment infos for node/python/conda environments
# GIT_PROMPT_VIRTUAL_ENV_AFTER_PROMPT=1 # uncomment to place virtual environment infos between prompt and git status (instead of left to the prompt)

# GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch
# GIT_PROMPT_SHOW_UNTRACKED_FILES=normal # can be no, normal or all; determines counting of untracked files
# GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch
# GIT_PROMPT_SHOW_UNTRACKED_FILES=normal # can be no, normal or all; determines counting of untracked files

# GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=0 # uncomment to avoid printing the number of changed files
# GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=0 # uncomment to avoid printing the number of changed files

# GIT_PROMPT_STATUS_COMMAND=gitstatus_pre-1.7.10.sh # uncomment to support Git older than 1.7.10
# GIT_PROMPT_STATUS_COMMAND=gitstatus_pre-1.7.10.sh # uncomment to support Git older than 1.7.10

# GIT_PROMPT_START=... # uncomment for custom prompt start sequence
# GIT_PROMPT_END=... # uncomment for custom prompt end sequence
# GIT_PROMPT_START=... # uncomment for custom prompt start sequence
# GIT_PROMPT_END=... # uncomment for custom prompt end sequence

# as last entry source the gitprompt script
# GIT_PROMPT_THEME=Custom # use custom theme specified in file GIT_PROMPT_THEME_FILE (default ~/.git-prompt-colors.sh)
# GIT_PROMPT_THEME_FILE=~/.git-prompt-colors.sh
# GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme
source ~/.bash-git-prompt/gitprompt.sh
# as last entry source the gitprompt script
# GIT_PROMPT_THEME=Custom # use custom theme specified in file GIT_PROMPT_THEME_FILE (default ~/.git-prompt-colors.sh)
# GIT_PROMPT_THEME_FILE=~/.git-prompt-colors.sh
# GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme
source ~/.bash-git-prompt/gitprompt.sh
```

You can set the `GIT_PROMPT_SHOW_UNTRACKED_FILES` variable to `no` or `normal` to speed things up if you have lots of
Expand All @@ -189,7 +159,7 @@ GIT_PROMPT_THEME=Solarized
If you set `GIT_PROMPT_THEME` to `Custom`, then the `.git-prompt-colors.sh` in the home directory will be used.
This file can now be generated with the command `git_prompt_make_custom_theme [<Name of base theme>]`. If the name of
the base theme is ommitted or the theme file is not found, then the Default theme is used. If you have already a custom
`.git-prompt-colors.sh` in your home directory, a error message will be shown.
`.git-prompt-colors.sh` in your home directory, an error message will be shown.

You can display a list of available themes with `git_prompt_list_themes` (the current theme is highlighted)

Expand Down Expand Up @@ -382,6 +352,9 @@ Please leave a comment on the issue, that you want to fix it, so others know, th

Pull requests are welcome. I will check them and merge them, if I think they help the project.

## Similar projects
https://github.com/ohmybash/oh-my-bash

## Donations
I accept tips through [Flattr][flattr].

Expand Down
16 changes: 8 additions & 8 deletions bash-git-prompt.spec
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
%global START_TOKEN ### Generated by %{name} rpm package
%global END_TOKEN ### Generated by %{name} rpm package

Name: bash-git-prompt
Version: 2.7.1
Release: 1%{?dist}
Summary: Informative git prompt for bash and fish
Name: bash-git-prompt
Version: 2.7.1
Release: 1%{?dist}
Summary: Informative git prompt for bash and fish

Group: Development/Tools
License: FreeBSD
URL: https://github.com/magicmonty/bash-git-prompt
Source0: https://github.com/magicmonty/%{name}/archive/%{name}-%{version}.tar.gz
Group: Development/Tools
License: BSD-2-Clause
URL: https://github.com/magicmonty/bash-git-prompt
Source0: https://github.com/magicmonty/%{name}/archive/%{version}/%{name}-%{version}.tar.gz
Requires: git
BuildArch: noarch

Expand Down
57 changes: 38 additions & 19 deletions git-prompt-help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
git_prompt_help() {
source "${__GIT_PROMPT_DIR}/prompt-colors.sh"
source "${__GIT_PROMPT_DIR}/themes/Default.bgptheme"

cat <<EOF | sed 's/\\\[\\033//g' | sed 's/\\\]//g'
The git prompt format is ${GIT_PROMPT_PREFIX}<BRANCH><TRACKING>${GIT_PROMPT_SEPARATOR}<LOCALSTATUS>${GIT_PROMPT_SUFFIX}
The git prompt format is ${GIT_PROMPT_PREFIX}<BRANCH><TRACKING>${GIT_PROMPT_SEPARATOR}<LOCALSTATUS>${GIT_PROMPT_SUFFIX}${ResetColor}

BRANCH is a branch name, such as "master" or "stage", a tag name, or commit
hash prefixed with ':'.
BRANCH is a branch name, such as "${GIT_PROMPT_MASTER_BRANCH}master${ResetColor}" or "${GIT_PROMPT_BRANCH}stage${ResetColor}", a tag name, or commit
${GIT_PROMPT_SYMBOLS_PREHASH}hash${ResetColor} prefixed with '${GIT_PROMPT_SYMBOLS_PREHASH:-':'}${ResetColor}'.

TRACKING indicates how the local branch differs from the
remote branch. It can be empty, or one of:

${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${ResetColor} - ahead of remote by N commits
${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - behind remote by M commits
${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - branches diverged, other by M commits, yours by N commits
${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}M${GIT_PROMPT_SYMBOLS_AHEAD}N${ResetColor} - branches diverged, other by M commits, yours by N commits

LOCALSTATUS is one of the following:

Expand All @@ -34,43 +35,61 @@ EOF
help_git_prompt() { git_prompt_help ; }

git_prompt_examples() {

format_branch() {
case "$1" in
${GIT_PROMPT_MASTER_BRANCHES})
echo "${GIT_PROMPT_MASTER_BRANCH}$1${ResetColor}"
;;
*)
echo "${GIT_PROMPT_BRANCH}$1${ResetColor}"
;;
esac
}
local p="${GIT_PROMPT_PREFIX}"
local s="${GIT_PROMPT_SUFFIX}${ResetColor}"

cat <<EOF | sed 's/\\\[\\033//g' | sed 's/\\\]//g'
These are examples of the git prompt:

[${GIT_PROMPT_BRANCH}master${ResetColor}${GIT_PROMPT_REMOTE}↑·3${ResetColor}|${GIT_PROMPT_CHANGED}1${ResetColor}] - on branch "master", ahead of remote by 3 commits, 1
file changed but not staged
${p}`format_branch master`${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}3${ResetColor}|${GIT_PROMPT_CHANGED}1${ResetColor}${s} - on branch "master", ahead of remote by 3 commits, 1
file changed but not staged

[${GIT_PROMPT_BRANCH}status${ResetColor}|${GIT_PROMPT_STAGED}2${ResetColor}] - on branch "status", 2 files staged
${p}`format_branch status`${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_STAGED}2${ResetColor}${s} - on branch "status", 2 files staged

[${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_CHANGED}7${GIT_PROMPT_UNTRACKED}${ResetColor}] - on branch "master", 7 files changed, some files untracked
${p}`format_branch master`${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_CHANGED}7${GIT_PROMPT_UNTRACKED}${ResetColor}${s} - on branch "master", 7 files changed, some files untracked

[${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_CONFLICTS}2${GIT_PROMPT_CHANGED}3${ResetColor}] - on branch "master", 2 conflicts, 3 files changed
${p}`format_branch master`${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_CONFLICTS}2${GIT_PROMPT_CHANGED}3${ResetColor}${s} - on branch "master", 2 conflicts, 3 files changed

[${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_STASHED}2${ResetColor}] - on branch "master", 2 stash entries
${p}`format_branch master`${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_STASHED}2${ResetColor}${s} - on branch "master", 2 stash entries

[${GIT_PROMPT_BRANCH}experimental${ResetColor}${GIT_PROMPT_REMOTE}↓·2↑·3${ResetColor}|${GIT_PROMPT_CLEAN}${ResetColor}]
- on branch "experimental"; your branch has diverged
${p}`format_branch experimental`${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}2${GIT_PROMPT_SYMBOLS_AHEAD}3${ResetColor}${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_CLEAN}${ResetColor}${s}
- on branch "experimental"; your branch has diverged
by 3 commits, remote by 2 commits; the repository is
otherwise clean

[${GIT_PROMPT_BRANCH}:70c2952${ResetColor}|${GIT_PROMPT_CLEAN}${ResetColor}] - not on any branch; parent commit has hash "70c2952"; the
repository is otherwise clean
${p}${GIT_PROMPT_BRANCH}${GIT_PROMPT_SYMBOLS_PREHASH}70c2952${ResetColor}${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_CLEAN}${ResetColor}${s} - not on any branch; parent commit has hash "70c2952"; the
repository is otherwise clean

${p}`format_branch extra-features`${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING}${ResetColor}${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_CHANGED}2${GIT_PROMPT_UNTRACKED}4${ResetColor}${s}
- on branch "extra-features"; no remote set (signalled by '${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING}${ResetColor}'),
2 files changed and 4 untracked files exist
EOF
}

git_prompt_color_samples() {

showColor() {
local color=$(eval echo "\${${1}}")
echo -e "${color}${1}${ResetColor}" | sed 's/\\\]//g' | sed 's/\\\[//g'
}

local x=0
while (( x < 8 )) ; do
showColor "${ColorNames[x]}"
showColor "Dim${ColorNames[x]}"
showColor "Bold${ColorNames[x]}"
showColor "Bright${ColorNames[x]}"
showColor "${ColorNames[@]:$x:1}"
showColor "Dim${ColorNames[@]:$x:1}"
showColor "Bold${ColorNames[@]:$x:1}"
showColor "Bright${ColorNames[@]:$x:1}"
(( x++ ))
done
}
Loading