Giter Club home page Giter Club logo

bash-git-prompt's Introduction

Informative git prompt for bash and fish

Gitter

This prompt is a port of the "Informative git prompt for zsh" which you can find here

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.

gitstatus.sh and git-prompt-help.sh added by AKS.

Examples

The prompt may look like the following:

Example prompt

  • (master↑3|✚1): on branch master, ahead of remote by 3 commits, 1 file changed but not staged
  • (status|●2): on branch status, 2 files staged
  • (master|✚7…): on branch master, 7 files changed, some files untracked
  • (master|✖2✚3): on branch master, 2 conflicts, 3 files changed
  • (master|⚑2): on branch master, 2 stash entries
  • (experimental↓2↑3|✔): on branch experimental; your branch has diverged by 3 commits, remote by 2 commits; the repository is otherwise clean
  • (:70c2952|✔): not on any branch; parent commit has hash 70c2952; the repository is otherwise clean

Prompt Structure

By default, the general appearance of the prompt is::

(<branch> <upstream branch> <branch tracking>|<local status>)

The symbols are as follows:

  • Local Status Symbols
    • : repository clean
    • ●n: there are n staged files
    • ✖n: there are n files with merge conflicts
    • ✖-n: there are n staged files waiting for removal
    • ✚n: there are n changed but unstaged files
    • …n: there are n untracked files
    • ⚑n: there are n stash entries
  • Upstream branch
    • Shows the remote tracking branch
    • Disabled by default
    • Enable by setting GIT_PROMPT_SHOW_UPSTREAM=1
  • Branch Tracking Symbols
    • ↑n: ahead of remote by n commits
    • ↓n: behind remote by n commits
    • ↓m↑n: branches diverged, other by m commits, yours by n commits
    • L: local branch, not remotely tracked
  • Branch Symbol:
    • When the branch name starts with a colon :, it means it's actually a hash, not a branch (although it should be pretty clear, unless you name your branches like hashes :-)

Installation

via Homebrew on Mac OS X

  • Run brew update

  • Run brew install bash-git-prompt for the last stable release or brew install --HEAD bash-git-prompt for the latest version directly from the repository

  • Now you can source the file in your ~/.bash_profile as follows:

if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then
  __GIT_PROMPT_DIR=$(brew --prefix)/opt/bash-git-prompt/share
  GIT_PROMPT_ONLY_IN_REPO=1
  source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
fi

via Git clone

  • Clone this repository to your home directory.
git clone https://github.com/magicmonty/bash-git-prompt.git ~/.bash-git-prompt --depth=1

Add to the ~/.bashrc:

if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then
    GIT_PROMPT_ONLY_IN_REPO=1
    source "$HOME/.bash-git-prompt/gitprompt.sh"
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 to that path

  • To install as an option in the fish_config GUI

sudo install -m 666 gitprompt.fish /usr/share/fish/tools/web_config/sample_prompts/
fish_config

 to install the bash-git-prompt as a choice under the prompt tab of the web config. Selecting this will copy it to ~/.config/fish/functions/fish_prompt.fish

  • You can also do
mkdir -p ~/.config/fish/functions/
cp gitprompt.fish ~/.config/fish/functions/fish_prompt.fish

 to overwrite the current prompt with the bash-git-prompt directly

All configs for .bashrc

# 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_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_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_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

You can set the GIT_PROMPT_SHOW_UNTRACKED_FILES variable to no or normal to speed things up if you have lots of untracked files in your repository. This can be the case for build systems that put their build artifacts in the subdirectory structure of the git repository. Setting it to all will count all untracked files, including files listed in .gitignore.

  • cd to a git repository and test it!

Themes

The most settings are now stored in theme files. To select a theme, set the variable GIT_PROMPT_THEME to the name of the theme located in <INSTALLDIR>/themes without the extension .bgptheme like this:

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, an error message will be shown.

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

If you omit the GIT_PROMPT_THEME variable, the Default theme is used or, if you have a custom .git-prompt-colors.sh in your home directory, then the Custom theme is used.

Ubuntu Themes

Ubuntu requires a bit more spacing for some characters so it has its own themes.

These can be listed with git_prompt_list_themes:

git_prompt_list_themes | grep Ubuntu
Theme structure

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

A theme consists of a function override_git_prompt_colors() which defines at least the variable GIT_PROMPT_THEME_NAME with a unique theme identifier and a call to the function reload_git_prompt_colors <ThemeName> like follows:

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.

If you use a custom theme in .git-prompt-colors.sh, please set GIT_PROMPT_THEME_NAME="Custom".

Further customizations

  • You can define GIT_PROMPT_START and GIT_PROMPT_END to tweak your prompt.

  • The default colors are defined within prompt-colors.sh, which is sourced by gitprompt.sh. The colors used for various git status are defined in themes/Default.bgptheme. Both of these files may be overridden by copying them to $HOME with a . prefix. They can also be placed in $HOME/lib without the leading .. The defaults are the original files in the ~/.bash-git-prompt directory.

  • You can use GIT_PROMPT_START_USER, GIT_PROMPT_START_ROOT, GIT_PROMPT_END_USER and GIT_PROMPT_END_ROOT in your .git-prompt-colors.sh to tweak your prompt. You can also override the start and end of the prompt by setting GIT_PROMPT_START and GIT_PROMPT_END before you source the gitprompt.sh.

  • The current git repo information is obtained by the script gitstatus.sh.

  • You can define prompt_callback function to tweak your prompt dynamically.

prompt_callback() {
    if [ $(jobs | wc -l) -ne 0 ]; then
        echo -n " jobs:\j"
    fi
}
  • There are two helper functions that can be used within prompt_callback:

    • gp_set_window_title <String> - sets the window title to the given string (should work for XTerm type terminals like in OS X or Ubuntu)
    • gp_truncate_pwd - a function that returns the current PWD truncated to fit the current terminal width. Specify the length to truncate to as a parameter. Otherwise it defaults to 1/3 of the terminal width.
  • If you want to show the git prompt only if you are in a git repository you can set GIT_PROMPT_ONLY_IN_REPO=1 before sourcing the gitprompt script

  • You can show an abbreviated username/repo in the prompt by setting GIT_PROMPT_WITH_USERNAME_AND_REPO=1 and setting the placeholder _USERNAME_REPO_ in your GIT_PROMPT_PREFIX. You can also add a GIT_PROMPT_USERNAME_REPO_SEPARATOR=" | " so the username/repo is nicely separated if there is a remote and if there is no remote, neither the username/repo part nor the separator will be shown. See the theme Single_line_username_repo.bgptheme for an example.

  • There is an indicator at the start of the prompt, which shows the result of the last executed command by if you put the placeholder _LAST_COMMAND_INDICATOR_ in any of the prompt templates. It is now by default activated in the default theme:

  GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"
  GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}"

If you want to display the exit code too, you can use the placeholder _LAST_COMMAND_STATE_ in GIT_PROMPT_COMMAND_OK or GIT_PROMPT_COMMAND_FAIL in your .git-prompt-colors.sh:

GIT_PROMPT_COMMAND_OK="${Green}" # displays as ✔
GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 for exit code 1
  • It is now possible to disable the fetching of the remote repository either globally by setting GIT_PROMPT_FETCH_REMOTE_STATUS=0 in your .bashrc or on a per repository basis by creating a file named .bash-git-rc with the content FETCH_REMOTE_STATUS=0 in the root of your git repository.

  • You can also ignore a repository completely by creating a file named .bash-git-rc with the content GIT_PROMPT_IGNORE=1 in the root of your git repository.

  • If you have a repository with many untracked files, the git prompt can become very slow. You can disable the display of untracked files on a per repository basis by setting GIT_PROMPT_SHOW_UNTRACKED_FILES=no in your .bash-git-rc in the repository or by disabling it globally in your .bashrc

  • If you have a repository with a deep submodule hierarchy, this can also affect performance. You can disable searching for changes in submodules on a per repository basis by setting GIT_PROMPT_IGNORE_SUBMODULES=1 in your .bash-git-rc

  • You can get help on the git prompt with the function git_prompt_help. Examples are available with git_prompt_examples. A list of all available named colors is available with git_prompt_color_samples

  • If you make any changes to any file that is sourced by gitprompt.sh, you should run this command, so that the next prompt update will find all the files and source them anew.

git_prompt_reset
  • You can disable/enable gitprompt by running:
git_prompt_toggle

Enjoy!

Alternative RPM Install

This project ships an RPM spec to simplify installation on RHEL and clones. If you wish to install from RPM, you may first build the RPM from scratch by following this procedure:

  • Clone this repository and tag the release with a version number
git tag -a -m "Tag release 1.1" 1.1
  • Run the following command to create a tarball:
VER=$(git describe)
# replace dash with underscore to work around
# rpmbuild does not allow dash in version string
VER=${VER//\-/_}
git archive                                \
    --format tar                           \
    --prefix=bash-git-prompt-${VER}/       \
    HEAD                                   \
    --  *.sh                               \
        *.fish                             \
        README.md                          \
        themes                             \
    > bash-git-prompt-${VER}.tar
mkdir -p /tmp/bash-git-prompt-${VER}
sed "s/Version:.*/Version:        ${VER}/"          \
    bash-git-prompt.spec                            \
    > /tmp/bash-git-prompt-${VER}/bash-git-prompt.spec
OLDDIR=$(pwd)
cd /tmp
tar -uf ${OLDDIR}/bash-git-prompt-${VER}.tar      \
        bash-git-prompt-${VER}/bash-git-prompt.spec
cd ${OLDDIR}
gzip bash-git-prompt-${VER}.tar
mv bash-git-prompt-${VER}.tar.gz bash-git-prompt-${VER}.tgz
  • Log into an RHEL or clones host and run:
rpmbuild -ta bash-git-prompt-xxx.tar.gz

Then you may publish or install the rpm from "~/rpmbuild/RPMS/noarch".

License

This code is under the BSD 2 Clause (NetBSD) license.

Who Are You?

The current maintainer of the original bash-git-prompt is Martin Gondermann.

Contributing

If you want to contribute you can look for issues with the label up-for-grabs. Please leave a comment on the issue, that you want to fix it, so others know, the labels are "taken".

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

Similar projects

Donations

I accept tips through Flattr.

Flattr

bash-git-prompt's People

Contributors

aks avatar drvanscott avatar guenhter avatar gullevek avatar hotpocket avatar iliakan avatar jaketesler avatar krazedkrish avatar ksinkar avatar linuxmaniac avatar maddingo avatar magicmonty avatar mariuszs avatar mplew-is avatar mrakitin avatar mskalski avatar norbertronecker avatar norbertszivos avatar ogr3 avatar pedantic79 avatar petli1m avatar plague-doctor avatar prograwertyk avatar rakotomandimby avatar rkitover avatar stas00 avatar stephankn avatar tessus avatar thomasrebele avatar vitaly-zdanevich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bash-git-prompt's Issues

Latest version barfs on OS X

On standard bash in OS X:
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright (C) 2007 Free Software Foundation, Inc.

This appears now when loading bash prompt:
-bash: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
-bash: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]

Can't see anything in Centos box

I am running this on my ubuntu, running perfectly. But I also have a Centos running on my machine on a virtualbox. When I implement this tool I can only the time stamp but not the git branch name or anything.

Is that tested with Centos. Can you please tell me what can be the reason.

For that reason I am using another solution for my Centos box, but I really wanted this one to work for me.
This is what happnes:
image

admin@muhammadr ~/.bash-git-prompt (master) $ ll
total 64
-rwxr--r-- 1 admin admin 2962 Oct 1 15:49 gitprompt.fish
-rwxr--r-- 1 admin admin 22550 Oct 1 15:49 gitprompt.png
-rw-r--r-- 1 admin admin 5181 Oct 8 16:01 gitprompt.sh
-rwxr--r-- 1 admin admin 2767 Oct 1 15:49 gitstatus.py
-rwxr--r-- 1 admin admin 2430 Oct 1 15:49 README.md
admin@muhammadr ~/.bash-git-prompt (master) $ source gitprompt.sh
~/.bash-git-prompt
10:47 $

PROMPT_COMMAND=$PROMPT_COMMAND;setGitPrompt doesn't work

Running fresh install of Ubuntu 13.04. When revert back to PROMPT_COMMAND=setGitPrompt, everything works fine.

Here's what I got to work:

if [ -z "$PROMPT_COMMAND" ]; then
  PROMPT_COMMAND=setGitPrompt
else
  PROMPT_COMMAND="$PROMPT_COMMAND;setGitPrompt"
fi

This code uses quotes to properly concatenate existing commands, but also checks if the there is no prior-defined commands and skips the concatenation.

"Enter passphrase for key ..." sometimes displays after prompt

I am using GitHub with the SSH access method, which I don't understand in the least, but I know how to follow directions, and I followed the directions given to me in the Git Workflow document for the project I am working on. I find that when using bash-git-prompt, the prompt sometimes adds the phrase "Enter passphrase for key ..." followed by the name of the file containing the SSH key for GitHub. It doesn't always appear, but seems kind of random - like once every 10 prompts or so. I guess something done in gitstatus.sh is executing a command that triggers this but isn't successfully filtering it out. Seems harmless - the command isn't actually waiting for input, and the prompt doesn't look malformed otherwise. but it is kind of annoying.

I realize that's practically no information to go on, but still, I'd love to see this fixed.

Git prompt as callable function

I was wondering if it would be possible to have a function that I can call from within my PS1 to make customization easier. For example, something like:

PS1='\u@\h:\W\[\033[01;33m\]$(__git_prompt)\[\033[00m\]$ '

Terminal title is not set

Consider changing the last line of gitprompt.sh to

PROMPT_COMMAND=$PROMPT_COMMAND;setGitPrompt

This would allow previous PROMPT_COMMAND:s to for example set window title.

Theme falls back to Default

The check always returns true, even if the file is readable:

if [[ !(-r $__GIT_PROMPT_THEME_FILE) ]]; then
        GIT_PROMPT_THEME="Default"
        __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE
fi

My bash version is GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin13). It is quite fishy to me, but it is fixed by dropping a space between ! and ( tokens.

if [[ ! (-r $__GIT_PROMPT_THEME_FILE) ]]; then
        GIT_PROMPT_THEME="Default"
        __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE
fi

Too slow for large repositories

The bash git prompt is extremely slow for large repositories. Its taking about 10 seconds after I press enter.

Is there a way to modify/disable prompt for certain repositories using .bash-git-rc ? I tried adding GIT_PROMPT_FETCH_REMOTE_STATUS=0 but its still extremely slow.

gitprompt.fish needs update

As I don't use the fish shell, I have no experience in fish scripting.
The gitprompt.fish is way behind the gitprompt.sh in functionality.

If you accept the challenge, your task is, to update the gitprompt.fish to the same functionality as the gitprompt.sh

How do I change the remote?

This script compares between local and origin. How do I change it to compare to a different remote? Thanks!

Can't get it to work in Ubuntu 13.10

Put line to the end of my ~/.bashrc
~/.bash-git-prompt/gitprompt.sh

Got error:
/home/larionov/.bash-git-prompt/gitprompt.sh: 3: /home/larionov/.bash-git-prompt/gitprompt.sh: Syntax error: "(" unexpected

So I changed a line !#/bin/sh to !#/bin/bash and it's still doesn't work, but without any error messages.

Async display

Do you know if it is possible to code this so that the the prompt is displayed immediately, and then later display the git info when it has been pulled down from the network? The delay for displaying the prompt can be quite large (a few seconds) and it is enough to be annoying. I imagine it is even worse on a slow connection. This is the nicest prompt I've ever seen, so it would be great if it could work in this manner. My knowledge of bash is very limited, but I would be happy to work on this if you believe it is possible without breaking the UI.

Cheers

mixing bash-git-prompt and debian style

This is a great idea and I quite like it, but I'd like to mix the git prompt with "classic" debian style (user@host and pwd)

I tried to add bits of the original PS1 to PROMPT_END, but I'm not a bash wizard and my syntax is never completely correct.
Any suggestions?

Reference: Debian .bashrc:

    case "$TERM" in
    xterm*|rxvt*)
        PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
        ;;
    *)
        ;;
    esac

Make some gitstatus variables configurable

The gitstatus.sh file contains these:

# change those symbols to whatever you prefer
symbols_ahead='↑·'
symbols_behind='↓·'
symbols_prehash=':'

It would be very handful if those var could be customizable like GIT_PROMPT_START or GIT_PROMPT_END (and some others) which are customizable adding them in a .git-prompt-colors.sh file.

scrolling through bash history adds characters to front of string

If I scroll back through my bash history then come back to the most recent command there are some extra characters added to the front of the string.

09:35 $ ruecho "test" test

Once I've picked up the extra characters, i'm unable to delete them. I can however ctrl-C to get rid of them.

Note that the command actually executes without the ru characters interfering.

Taking too long to refresh.

Hey.

Every time I cd into a new repository or just press return, it takes too long to show me the prompt. It seems that it is fetching the remote repository.

Is it normal to be that slow or just happens with me?

GIT_PROMPT_END not working

I did a git pull this morning and my custom prompt no longer works.

The behavior I see is that when I'm in a git repo, the prompt works fine, but when I'm not in a repo my prompt loses the GIT_PROMPT_END setting.

Screenshot of good and bad prompts:
image

After doing a git bitsect to find the commit that broke the prompt, I got this:

ff7575ccdcc556e5ffb591bff85b8b7ac4e2f985 is the first bad commit
commit ff7575ccdcc556e5ffb591bff85b8b7ac4e2f985
Author: Martin Goldhahn <[email protected]>
Date:   Sun Aug 4 19:06:28 2013 +0200

    apply git prompt only on directories belonging to a git repository

:000000 100644 0000000000000000000000000000000000000000 e7683df559d8d3dd9e7761a01777940608f18654 A      .gitignore
:100644 100644 f9e5c69e6ab45c171994beaef04c9a24559efd10 cb7254dbf6efebbcafb9efae5c58ab862996702b M      gitprompt.sh

Here's my custom prompt setup:

PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]"
GIT_PROMPT_START=$PS1
GIT_PROMPT_END="\n[\t]$ "
source ~/.bash/bash-git-prompt/gitprompt.sh

No updated git-prompt-colors.sh in the installation directory.

The new read me says "Please see the updated git-prompt-colors.sh in the installation directory!"

However, I looking around I don't see this updated file. I have looked in /usr/local/Cellar/bash-git-prompt/2.2/share/ where there is a prompt.colors.sh, but that does not seem to be it.

-- Christopher Allen

Untracked files differ

Hi,

I have noticed that the number of untracked files shown on the prompt change if I enter in a subfolder.

screenshot from 2013-10-10 10 30 33

Is that normal behavior?

GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR does not working

hi,
even if i set
GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1
just before i source ~/.bash-git-prompt/gitprompt.sh
the pompt always give mi success prompt and never failure even if the last command gives not 0.

anyway it'd be also useful in case of failure the last return value would be printed eg:
✘-1

Get rid of GIT_PROMPT_SYMBOLS_AHEAD simbol

Hello,

I created a custom theme, then in my .bash_profile:

# .bash_profile
GIT_PROMPT_THEME=Mine
GIT_PROMPT_ONLY_IN_REPO=1
source ~/bash-git-prompt/gitprompt.sh

then in my theme Mine.bgptheme:

# ~/bash-git-prompt/themes/Mine.bgptheme
GIT_PROMPT_SYMBOLS_AHEAD=""
GIT_PROMPT_SYMBOLS_BEHIND=""
GIT_PROMPT_SYMBOLS_PREHASH=":"

The whole theme seems working, however I still get the default ahead and behind simbols with the dot:

# original 
 # Please do not add colors to these symbols
  GIT_PROMPT_SYMBOLS_AHEAD="↑·"         # The symbol for "n versions ahead of origin"
  GIT_PROMPT_SYMBOLS_BEHIND="↓·"        # The symbol for "n versions behind of origin"
  GIT_PROMPT_SYMBOLS_PREHASH=":"        # Written before hash of commit, if no name could be found

My aim is to remove those dots within my theme and seems it's not working.
Any hint? Is this a bug?

_LAST_COMMAND_INDICATOR_ being printed in prompt output on root user

I installed this script on my CentOS server and it's working fine except that it's printing _LAST_COMMAND_INDICATOR_ in the output of my prompt after the actual last command indicator. For example:

✔ _LAST_COMMAND_INDICATOR_ ~/.bash-git-prompt [master|✚ 1]
09:30 #

✘-127 _LAST_COMMAND_INDICATOR_ ~/.bash-git-prompt [master|✚ 1]
09:34 #

I'm not sure how to fix this!

Consider support for Stacked Git (a.k.a. StGit, stg)

I use Stacked Git a lot and have been trying to think of a good way to incorporate it into bash-git-prompt.

Possible Unicode symbols to represent StGit-applied patches:

  • U+2591 (░, "light shade")
  • U+2592 (▒, "medium shade")
  • U+2593 (▓, "dark share")
  • U+25A9 (▩, "square with diagonal crosshatch fill")

Not founding the correct repository.

Hi.

I had set my home directory as a git repo that store all my config files. I forked your repo and have added it as a submodule to the previous repo.

The problem is that when I got to another repo, the branch that is informed do not change.

What is wrong?

captura de tela de 2013-07-05 15 21 32

login prompts for checkUpstream

If the remote repo is accessed via ssh and requests an login, then the checkUpstream will not work.

So, either the checkUpstream should be disabled if there is a login request or there should be documentation about this and how to avoid it (eg by creating a ssh key to login).

Error if no remotes (new repo)

In case of a new repo, there is no remote ref and so the "git fetch --quiet" on line 108 of gitprompt.sh generates an error:

fatal: No remote repository specified.  Please, specify either a URL or a
remote name from which new revisions should be fetched.
~/tmp [master|✔] 

I'm not git-savvy enough to be sure of the best way to prevent this; perhaps test for non-null from "git remote show"?
[[ -n $(git remote show) ]] && git fetch --quiet

Definig $PROMPT_START $PROMPT_END out of gitprompt.sh

According to installation, after clone we need to copy files to ".bash" folder, we also need to "source /home/%USER%/.bash/gitprompt.sh" to ~/.bashrc file.

if $PROMPT_START $PROMPT_END are changed by user it will be not that simple as "git pull" to update to latest version of bash-git-prompt.

Expected: $PROMPT_START $PROMPT_END variables have to be defined to default only if not defined before.
that will allow define all in ~/.bashrc file

if [ "$PROMPT_START" = "" ] ; then
PROMPT_START="$Yellow$PathShort$ResetColor"
fi
if [ "$PROMPT_END" = "" ] ; then
PROMPT_END=" \n$WHITE$Time12a$ResetColor $ "
fi

Don't change prompt when outside git repository

When outside a git repository leave the prompt as the default prompt. Currently it overrides it and shows no path info. Just the time which is something I'd never expect to see and doesn't really provide anything useful.

Changes to ~/.git-prompt-colors don't take when re-sourcing ~/.bashrc

Steps to reproduce:

  • git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt
  • Add source ~/.bash-git-prompt/gitprompt.sh to ~/.bashrc
  • source ~/.bashrc
  • cp ~/.bash-git-prompt/git-prompt-colors ~/.git-prompt-colors.sh
  • Make changes to ~/.git-prompt-colors.sh
  • source ~/.bashrc

Changes do not appear.

I believe this is because here the __GIT_PROMPT_COLORS_FILE variable is set to ~/.bash-git-prompt/git-prompt-colors.sh on the first run, when ~/.git-prompt-colors.sh doesn't exist.

Then ~/.git-prompt-colors.sh is created, but is never read when re-sourcing because this uses the old variable.

The only way to get the changes to appear is to manually set the environment variable or close out of the terminal.

Not sure if this is worth fixing, but perhaps it is worth mentioning as it took me a bit to figure out why my changes weren't appearing (normally I get something up and working before making config changes).

Prompt terminating Vim session

Sometimes when pressing ctrl-z to suspend vim to do some terminal work, I get the following message:

[1]+ Stopped vim src/networking/remoteserverbridge.cpp
bash: warning: deleting stopped job 1 with process group 15512

When trying to resume vim using fg after that, I get this:
02:26 $ fg
bash: fg: job has terminated
[2]+ Done { $1 &>/dev/null; }

This doesn't happen every single time I suspend it, but I can't even develop for 10 min before it happens, and it started to happen this evening which is the first evening I've been using bash-git-prompt and it has never ever happened before.

My system is Debian sid.

Last command indicator and GIT_PROMPT_START not playing well with each other

With GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1, I added the following setting:

 GIT_PROMPT_START="\n"

my intention being to have one blank line between any previous output and the current prompt.

However, the contents of GIT_PROMPT_START (a newline character in this case) are inserted after the last command indicator (whether ✔ or ✘), not before, as I would expect.

✘ 
~ [master|✚ 1]
20:18 $

I consider this a bug, as by "prompt start" I understand a position before any other prompt contents, including the last command indicator.

What does L mean?

This is a question, not an issue. When I create a new branch I see an L next to the branch name. What does this L mean? Thanks.

For .bashrc, test first before doing source?

Right you now say:

==> Caveats
You should add the following to your .bashrc (or equivalent):
  source /usr/local/opt/bash-git-prompt/share/gitprompt.sh   

Instead I suggest:

  if [ -f $(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh ]; then
    source $(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh
  fi

or if you prefer a single line:

  if [ -f $(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh ]; then source $(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh ; fi

Two reasons:

  1. If brew is installed in a non-standard location, this will still work.
  2. In during a new installation, you pull your .dotfiles from a repository, but you have not installed bash-git-prompt yet, your .bashrc file will not have an error in it.

-- Christopher Allen

How to customise the PS1

I tried to do this

GIT_PROMPT_START= echo "[Server]" # uncomment for custom prompt start sequence

Did not work

Symbol for local repo

What about the local repos?
Any variable within themes for that? :D

At the moment I see a uppercase letter 'L' , which is generated from gitstatus.sh

if [[ "$has_remote_tracking" == "0" ]] ; then
  remote='L'
fi 

It would be great to have a variable also for that

What does "L" signify as remote status?

My prompt is something along the lines of:

my_current_path [master L|✔]

What is the meaning of "L" in this instance? Do I understand correctly that it indicates that the remote branch is neither ahead of nor behind the local branch?

Many thanks.

Strange character

Hi!

I followed all the steps to install and seemingly everything worked correctly, but master's branch is always showing this way. Is this correct?

Thx,
Alexandre Rocco.

image

Can't see current virtualenv using virtualenvwrapper

Before i'm starting working with bash-git-prompt in my ~/.bashrc file

export WORKON_HOME="$HOME/.virtualenvs"
source /usr/local/bin/virtualenvwrapper.sh

All works ok, but then i add bash-git-prompt in my ~/.bashrc file virtualenvwrapper can't work normally.
For example i can't see current selected virtualenv in my bash prompt. I think bash-git-prompt override it not correctly.

GIT_PROMPT_ONLY_IN_REPO=1
source ~/.bash-git-prompt/gitprompt.sh

export WORKON_HOME="$HOME/.virtualenvs"
source /usr/local/bin/virtualenvwrapper.sh

I try to move bash-git-prompt after virtualenvwrapper, but get same problem.

Now i'm using last version of bash-git-prompt from master brunch.

disable prompt for home directory

Do you know easy way to disable prompt only for home directory or another workaround? I use this repo to sync config between the laptops. It is very annoying see prompt in every directory under $HOME. It even happens that i'm going to create new project, for example, at night, have created $HOME/repos/project, have started working on it( haven't initialized yet), and on next day seeing that repository clean and when i'm ready to add/commit, do this action on wrong "home config" repo. Sorry, if example is not very good.

Solarized prompt-color.sh & git-prompt-color.sh

I like that I can now put my prompt under brew install bash-git-prompt control, however, I found it difficult to figure out how to make it work with the solarized-dark and solarized-light themes that I use in my terminal. As these colors are very popular, can you offer an alternative prompt-color.sh & git-prompt-color.sh that are solarized?

Thanks!

-- Christopher Allen

Undesired output

Sometimes commands complete and spit out the following to the screen.

[1]+  Done                    { $1 >&/dev/null; }

This seems to only have happened after the latest merge.

RPM spec needs update

The RPM spec is outdated. As I currently cannot do it by myself, someone should update the bash-git-prompt.spec to reflect the changes with the themes

overlapping chars in committed files

screenshot - 180914 - 16 52 04

If you look at the right-hand terminal, you can see the chars have squashed together. I am using terminator on Ubuntu 14.04.

I fixed this before on my own branch about a year ago but never pushed upstream.

-  GIT_PROMPT_STAGED="${Red}● "          # the number of staged files/directories
+  GIT_PROMPT_STAGED="${Red}●"           # the number of staged files/directories
   GIT_PROMPT_CONFLICTS="${Red}✖ "       # the number of files in conflict
   GIT_PROMPT_CHANGED="${Blue}✚ "        # the number of changed files
-  GIT_PROMPT_REMOTE=" "                 # the remote branch name (if any)
-  GIT_PROMPT_UNTRACKED="${Cyan}… "      # the number of untracked files/dirs
+
+  GIT_PROMPT_REMOTE=" "                 # the remote branch name (if any) and the symbols for ahead an
+  GIT_PROMPT_UNTRACKED="${Cyan}…"       # the number of untracked files/dirs
   GIT_PROMPT_STASHED="${BoldBlue}⚑ "    # the number of stashed files/dir
-  GIT_PROMPT_CLEAN="${BoldGreen}✔ "     # a colored flag indicating a "clean" repo
+  GIT_PROMPT_CLEAN="${BoldGreen}✔"      # a colored flag indicating a "clean" repo

i.e. I added a space after the icons (that don't seem to want to obey monospacing or something). I assume this is only a problem with certain fonts/terminals and doesn't affect Terminal.app?

"Bad substitution" Version 1.0

This is the error on load terminal

.bash/gitprompt.sh: 6: /home/user/.bash/gitprompt.sh: Bad substitution

Environment:

Bash version 4.2.45(1)-release (x86_64-pc-linux-gnu)
S.O. Ubuntu 13.04 raring
Teminal Emulatos Terminator | Xfce Terminal | Xterm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.