From 0975f9dbf97124599fcb03dbb27de80c05a46e67 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Fri, 24 Jan 2014 10:09:15 -0800 Subject: [PATCH 01/99] aks:testing new file in local, but not in remote --- newfile.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newfile.txt diff --git a/newfile.txt b/newfile.txt new file mode 100644 index 0000000..e69de29 From 1552aafd8e81f36b4852cdb6702437c143b07e7e Mon Sep 17 00:00:00 2001 From: Gustavo Braganca Date: Fri, 16 May 2014 20:44:46 +0200 Subject: [PATCH 02/99] Adds support to show Conda environment on prompt When one uses a Virtualenv environment, its name is shown in the prompt. The same did not happen with a Conda environment. This fix it. --- gitprompt.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 33d4c16..49213d9 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -134,6 +134,8 @@ function git_prompt_config() else if [[ -n "${VIRTUAL_ENV}" ]]; then EMPTY_PROMPT="(${Blue}$(basename "${VIRTUAL_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}" + elif [[ -n "${CONDA_DEFAULT_ENV}" ]]; then + EMPTY_PROMPT="(${Blue}$(basename "${CONDA_DEFAULT_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}" else EMPTY_PROMPT="${PROMPT_START}$($prompt_callback)${PROMPT_END}" fi @@ -268,6 +270,10 @@ function updatePrompt() { PS1="(${Blue}$(basename ${VIRTUAL_ENV})${ResetColor}) ${PS1}" fi + if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then + PS1="(${Blue}$(basename ${CONDA_DEFAULT_ENV})${ResetColor}) ${PS1}" + fi + else PS1="${EMPTY_PROMPT}" fi @@ -310,4 +316,4 @@ function run { source "$__GIT_PROMPT_DIR/git-prompt-help.sh" } -run \ No newline at end of file +run From 71001b12156585a3b34bf47d95d738159df5d6ba Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Fri, 27 Jun 2014 22:17:34 +0200 Subject: [PATCH 03/99] Implemented the possibility for an indicator which shows the result of the last command. To enable just write export GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1 just before sourcing the gitprompt.sh fixes #60 --- README.md | 3 +++ git-prompt-colors.sh | 3 +++ gitprompt.sh | 24 ++++++++++++++++++------ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ce3102a..31ea14c 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,9 @@ function prompt_callback { - 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 additional indicator at the start of the prompt, which shows the result of the last executed command by setting ``GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1`` before sourcing the gitprompt script + + - You can get help on the git prompt with the function ``git_prompt_help``. Examples are available with ``git_prompt_examples``. diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index 355811c..73e10a8 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -16,6 +16,9 @@ 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_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 +GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}" GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " diff --git a/gitprompt.sh b/gitprompt.sh index 49213d9..03d288a 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -43,6 +43,7 @@ function git_prompt_config() local Red="\[\033[0;31m\]" local Blue="\[\033[0;34m\]" local Cyan="\[\033[0;36m\]" + local Green="\[\033[0;32m\]" #Checking if root to change output _isroot=false @@ -88,6 +89,8 @@ function git_prompt_config() GIT_PROMPT_UNTRACKED="${Cyan}…" GIT_PROMPT_STASHED="${BoldBlue}⚑" GIT_PROMPT_CLEAN="${BoldGreen}✔" + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}" @@ -97,7 +100,15 @@ function git_prompt_config() # Please do not add colors to these symbols GIT_PROMPT_SYMBOLS_AHEAD="↑·" GIT_PROMPT_SYMBOLS_BEHIND="↓·" - GIT_PROMPT_SYMBOLS_PREHASH=":" + GIT_PROMPT_SYMBOLS_PREHASH=":" + fi + + if [ "x${GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR}" == "x1" ]; then + if [ $LAST_COMMAND_STATE = 0 ]; then + LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_OK}"; + else + LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_FAIL}"; + fi fi if [ "x${GIT_PROMPT_START}" == "x" ]; then @@ -133,11 +144,11 @@ function git_prompt_config() EMPTY_PROMPT=$OLD_GITPROMPT else if [[ -n "${VIRTUAL_ENV}" ]]; then - EMPTY_PROMPT="(${Blue}$(basename "${VIRTUAL_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}" + EMPTY_PROMPT="${LAST_COMMAND_INDICATOR}(${Blue}$(basename "${VIRTUAL_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}" elif [[ -n "${CONDA_DEFAULT_ENV}" ]]; then - EMPTY_PROMPT="(${Blue}$(basename "${CONDA_DEFAULT_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}" + EMPTY_PROMPT="${LAST_COMMAND_INDICATOR}(${Blue}$(basename "${CONDA_DEFAULT_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}" else - EMPTY_PROMPT="${PROMPT_START}$($prompt_callback)${PROMPT_END}" + EMPTY_PROMPT="${LAST_COMMAND_INDICATOR}${PROMPT_START}$($prompt_callback)${PROMPT_END}" fi fi @@ -159,6 +170,7 @@ function git_prompt_config() } function setGitPrompt() { + LAST_COMMAND_STATE=$? local EMPTY_PROMPT local __GIT_STATUS_CMD @@ -204,13 +216,13 @@ function updatePrompt() { local GIT_PROMPT_UNTRACKED local GIT_PROMPT_STASHED local GIT_PROMPT_CLEAN + local LAST_COMMAND_INDICATOR local PROMPT_LEADING_SPACE local PROMPT_START local PROMPT_END local EMPTY_PROMPT local GIT_PROMPT_FETCH_TIMEOUT local __GIT_STATUS_CMD - local Blue="\[\033[0;34m\]" git_prompt_config @@ -265,7 +277,7 @@ function updatePrompt() { STATUS="${STATUS}${ResetColor}${GIT_PROMPT_SUFFIX}" - PS1="${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}" + PS1="${LAST_COMMAND_INDICATOR}${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}" if [[ -n "${VIRTUAL_ENV}" ]]; then PS1="(${Blue}$(basename ${VIRTUAL_ENV})${ResetColor}) ${PS1}" fi From 1b78dfb6c88bbb0c71cc0f2d1f91ada2dc9ddd89 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Tue, 1 Jul 2014 19:47:54 +0200 Subject: [PATCH 04/99] Implemented a per repository possibility to turn of the fetching of the remote status (fixes #59) --- gitprompt.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 03d288a..cbd3f3d 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -183,7 +183,15 @@ function setGitPrompt() { return fi - checkUpstream + local FETCH_REMOTE_STATUS=true + if [[ -e "${repo}/.bash-git-rc" ]]; then + source "${repo}/.bash-git-rc" + fi + + if [ "${FETCH_REMOTE_STATUS}" == "true" ]; then + checkUpstream + fi + updatePrompt } From f66e4e298410851c98d705a3f5b7992f1ed985ab Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Tue, 1 Jul 2014 20:09:32 +0200 Subject: [PATCH 05/99] Added a configuration variable to globally disable the remote fetching (also fix for #59) --- gitprompt.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index cbd3f3d..5f106c6 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -183,12 +183,16 @@ function setGitPrompt() { return fi - local FETCH_REMOTE_STATUS=true + local FETCH_REMOTE_STATUS=1 + if [[ "x${GIT_PROMPT_FETCH_REMOTE_STATUS}" == "x0" ]]; then + FETCH_REMOTE_STATUS=0 + fi + if [[ -e "${repo}/.bash-git-rc" ]]; then source "${repo}/.bash-git-rc" fi - if [ "${FETCH_REMOTE_STATUS}" == "true" ]; then + if [ "x${FETCH_REMOTE_STATUS}" == "x1" ]; then checkUpstream fi From c32b48bdfe7ce330900a2aa95d0b3f37802fb884 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Tue, 1 Jul 2014 20:14:39 +0200 Subject: [PATCH 06/99] Updated README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 31ea14c..4f4158f 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,8 @@ function prompt_callback { - You can show an additional indicator at the start of the prompt, which shows the result of the last executed command by setting ``GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1`` before sourcing the gitprompt script +- 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 get help on the git prompt with the function ``git_prompt_help``. Examples are available with ``git_prompt_examples``. From 877d1c2e813fd92f265b938089a564484ecb653f Mon Sep 17 00:00:00 2001 From: Matias Fernandez Date: Wed, 16 Jul 2014 19:01:18 -0300 Subject: [PATCH 07/99] Modify gitstatus.sh to detect local branch without tracking remote --- gitstatus.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gitstatus.sh b/gitstatus.sh index e64df13..ba210b5 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -111,6 +111,15 @@ else remote_ref="refs/remotes/$remote_name/${merge_name##refs/heads/}" fi + # detect if the local branch have a remote tracking branch + cmd_output=$(git rev-parse --abbrev-ref ${branch}@{upstream} 2>&1 >/dev/null) + + if [ `count_lines "$cmd_output" "fatal: No upstream"` == 1 ] ; then + has_remote_tracking=0 + else + has_remote_tracking=1 + fi + # get the revision list, and count the leading "<" and ">" revgit=`git rev-list --left-right ${remote_ref}...HEAD` num_revs=`all_lines "$revgit"` @@ -123,10 +132,15 @@ else remote="${remote}${symbols_ahead}${num_ahead}" fi fi + if [[ -z "$remote" ]] ; then remote='.' fi +if [[ "$has_remote_tracking" == "0" ]] ; then + remote='L' +fi + for w in "$branch" "$remote" $num_staged $num_conflicts $num_changed $num_untracked $num_stashed $clean ; do echo "$w" done From cc646ed6f18ea3d6151123e612703561b44fa8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20LASSERRE?= Date: Mon, 21 Jul 2014 16:02:26 +0200 Subject: [PATCH 08/99] Update gitprompt.sh Remove trailing whitespaces --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 5f106c6..262bec1 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -100,7 +100,7 @@ function git_prompt_config() # Please do not add colors to these symbols GIT_PROMPT_SYMBOLS_AHEAD="↑·" GIT_PROMPT_SYMBOLS_BEHIND="↓·" - GIT_PROMPT_SYMBOLS_PREHASH=":" + GIT_PROMPT_SYMBOLS_PREHASH=":" fi if [ "x${GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR}" == "x1" ]; then From e0183531c307a2d7b4411474b91bf165beb99da7 Mon Sep 17 00:00:00 2001 From: Justin Zhang Date: Fri, 8 Aug 2014 16:52:21 +0800 Subject: [PATCH 09/99] Add spec file to build rpm package --- README.md | 46 ++++++++++++++++++++++++++++ bash-git-prompt.spec | 72 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 bash-git-prompt.spec diff --git a/README.md b/README.md index 4f4158f..5c7f5b1 100644 --- a/README.md +++ b/README.md @@ -103,4 +103,50 @@ function prompt_callback { **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 + +````sh + git tag -a -m "Tag release 1.1" 1.1 +```` + +* Run the following command to create a tarball: + +````sh + VER1=$(git describe) + # replace dash with underscore to work around + # rpmbuild does not allow dash in version string + VER=${VER1//\-/_} + git archive \ + --format tar \ + --prefix=bash-git-prompt-${VER}/ \ + HEAD \ + -- *.sh \ + *.py \ + *.fish \ + README.md \ + > 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: + +````sh +rpmbuild -ta bash-git-prompt-xxx.tar.gz +```` +Then you may publish or install the rpm from "~/rpmbuild/RPMS/noarch". + [blog post]: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ diff --git a/bash-git-prompt.spec b/bash-git-prompt.spec new file mode 100644 index 0000000..a381b78 --- /dev/null +++ b/bash-git-prompt.spec @@ -0,0 +1,72 @@ +%global START_TOKEN ### Generated by %{name} rpm package +%global END_TOKEN ### Generated by %{name} rpm package + +Name: bash-git-prompt +Version: 1.0 +Release: 1%{?dist} +Summary: Informative git prompt for bash and fish + +Group: Development/Tools +License: GPL +URL: https://github.com/magicmonty/bash-git-prompt.git +Source0: https://github.com/magicmonty/bash-git-prompt/archive/%{name}-%{version}.tgz +Requires: git +BuildArch: noarch + +%description +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. + +This package will automatically enable the git prompt for bash after +install. It will disable the prompt accordingly after uninstall. + +%prep +%setup -q + + +%build + + +%install +rm -rf %{buildroot} + +install -d 755 %{buildroot}%{_datadir}/%{name} +install -pm 755 *.sh %{buildroot}%{_datadir}/%{name} +install -pm 755 *.py %{buildroot}%{_datadir}/%{name} +install -pm 755 *.fish %{buildroot}%{_datadir}/%{name} +install -pm 644 README.md %{buildroot}%{_datadir}/%{name} + +# never include compiled Python program +rm -fr %{buildroot}%{_datadir}/%{name}/*.pyo +rm -fr %{buildroot}%{_datadir}/%{name}/*.pyc + + +%clean +rm -rf %{buildroot} + + +%files +%defattr(-,root,root,-) +%{_datadir}/%{name} + + +%post +# enable bash-git-prompt +cat << EOF >> /etc/bashrc +%{START_TOKEN} +if [ -f %{_datadir}/%{name}/gitprompt.sh ]; then + # Set config variables first + + GIT_PROMPT_ONLY_IN_REPO=1 + source %{_datadir}/%{name}/gitprompt.sh +fi +%{END_TOKEN} +EOF + +%postun +# remove bash-git-prompt setup +sed -i -e '/^%{START_TOKEN}/, /^%{END_TOKEN}/{d}' /etc/bashrc + + +%changelog +* Fri Aug 08 2014 Justin Zhang Date: Thu, 28 Aug 2014 00:19:32 -0700 Subject: [PATCH 10/99] aks: refactor prompt color names & generation into separate file --- prompt-colors.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 prompt-colors.sh diff --git a/prompt-colors.sh b/prompt-colors.sh new file mode 100644 index 0000000..9249a7e --- /dev/null +++ b/prompt-colors.sh @@ -0,0 +1,82 @@ +# prompt-colors.sh +# +# source this file to get color definitions +# if $debug or $verbose is set, the definitions +# are also printed to STDERR. + +define_color_names() { + + ColorNames=( Black Red Green Yellow Blue Magneta Cyan White ) + FgColors=( 30 31 32 33 34 35 36 37 ) + BgColors=( 40 41 42 43 44 45 46 47 ) + + local AttrNorm=0 + local AttrBright=1 + local AttrDim=2 + local AttrUnder=4 + local AttrBlink=5 + local AttrRev=7 + local AttrHide=8 + + # define "BoldCOLOR", "BrightCOLOR", and "DimCOLOR" names + + # _map_colors ATTRNAME ATTRVALUE + # + # Defines three names for every color, attribute combintaion: + # {ATTRNAME}{COLORNAME} + # {ATTRNAME}{COLORNAME}Fg + # {ATTRNAME}{COLORNAME}Bg + # + # Example: BoldRed, BoldRedFg, BoldRedBg + + _map_colors() { + local x=0 + local attrname="$1" + local attrcode=$2 + while (( x < 8 )) ; do + local colorname=${ColorNames[x]} + local fgcolorcode=${FgColors[x]} + local bgcolorcode=${BgColors[x]} + longcolorname="${attrname}${colorname}" + _def_color $longcolorname $attrcode $fgcolorcode + _def_color ${longcolorname}Fg $attrcode $fgcolorcode + _def_color ${longcolorname}Bg $attrcode $bgcolorcode + (( x++ )) + done + } + + # _term_color [ N | N M ] + _term_color() { + local cv + if (( $# > 1 )); then + cv="${1};${2}" + else + cv="${1}" + fi + echo "\[\033[${cv}m\]" + } + + # def_color NAME ATTRCODE COLORCODE + _def_color() { + local def="$1=\"\`_term_color $2 $3\`\"" + if [[ -n "$debug$verbose" ]]; then + echo 1>&2 "+ $def" + fi + eval "$def" + } + + #ResetColor="`_term_color 0`" # Text reset + + _map_colors Bold $AttrBright + _map_colors Bright $AttrBright + _map_colors Dim $AttrDim + _map_colors '' $AttrNorm + + _def_color IntenseBlack 0 90 + _def_color ResetColor 0 0 + +} +define_color_names + +# end of prompt-colors.sh +# vim: set ai sw=2 From d89b35ad7c2b26cb46dccf3ea98efd8a338df5fd Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 00:20:00 -0700 Subject: [PATCH 11/99] aks: make the prompt vars all global --- git-prompt-colors.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index 686804c..56afa14 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -1,4 +1,17 @@ # These are the color definitions used by gitprompt.sh + + declare -g GIT_PROMPT_PREFIX + declare -g GIT_PROMPT_SUFFIX + declare -g GIT_PROMPT_SEPARATOR + declare -g GIT_PROMPT_BRANCH + declare -g GIT_PROMPT_STAGED + declare -g GIT_PROMPT_CONFLICTS + declare -g GIT_PROMPT_CHANGED + declare -g GIT_PROMPT_REMOTE + declare -g GIT_PROMPT_UNTRACKED + declare -g GIT_PROMPT_STASHED + declare -g GIT_PROMPT_CLEAN + GIT_PROMPT_PREFIX="[" # start of the git info string GIT_PROMPT_SUFFIX="]" # the end of the git info string GIT_PROMPT_SEPARATOR="|" # separates each item From 9eddd83375a9f323c85c32d2cdacb5f2fa1c1f87 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 00:21:28 -0700 Subject: [PATCH 12/99] aks: major rewrite with refactored colors, envar management --- gitprompt.sh | 221 ++++++++++++++++++++++++++------------------------- 1 file changed, 114 insertions(+), 107 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index f4ca70e..f4de844 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -22,92 +22,107 @@ function git_prompt_dir() fi } +# gp_set_file_var ENVAR SOMEFILE +# +# Set ENVAR to the path to SOMEFILE, based on $HOME, $__GIT_PROMPT_DIR, and the +# directory of the current script. The SOMEFILE can be prefixed with '.', or +# not. +# +# Return 0 (success) if ENVAR not already defined, 1 (failure) otherwise. + +function gp_set_file_var() { + local envar="$1" + local file="$2" + if eval "test -z \"\$$envar\"" ; then + eval "$envar=" # set empty envar + gp_maybe_set_envar_to_path "$envar" "$HOME/.$file" && return 0 + gp_maybe_set_envar_to_path "$envar" "$HOME/$file" && return 0 + gp_maybe_set_envar_to_path "$envar" "$HOME/lib/$file" && return 0 + git_prompt_dir + gp_maybe_set_envar_to_path "$envar" "$__GIT_PROMPT_DIR/$file" && return 0 + gp_maybe_set_envar_to_path "$envar" "${0##*/}/$file" && return 0 + fi + return 1 +} + +# gp_maybe_set_envar_to_path ENVAR FILEPATH +# +# return 0 (true) if FILEPATH is readable, set ENVAR to it +# return 1 (false) if not + +function gp_maybe_set_envar_to_path(){ + local envar="$1" + local file="$2" + if [[ -r "$file" ]]; then + eval "$envar=\"$file\"" + return 0 + fi + return 1 +} + function git_prompt_config() { - # Colors - ResetColor="\[\033[0m\]" # Text reset - - # Bold - local BoldGreen="\[\033[1;32m\]" # Green - local BoldBlue="\[\033[1;34m\]" # Blue - # High Intensty - local IntenseBlack="\[\033[0;90m\]" # Grey + # There are two files related to colors: + # + # prompt-colors.sh -- sets generic color names suitable for bash `PS1` prompt + # git-prompt-colors.sh -- sets the GIT_PROMPT color scheme, using names from prompt-colors.sh - # Bold High Intensty - local Magenta="\[\033[1;95m\]" # Purple + if gp_set_file_var __PROMPT_COLORS_SH prompt-colors.sh ; then - # Regular Colors - local Yellow="\[\033[0;33m\]" - local White='\[\033[37m\]' - local Red="\[\033[0;31m\]" - local Blue="\[\033[0;34m\]" - local Cyan="\[\033[0;36m\]" + if [[ -n "${__PROMPT_COLORS_SH}" ]]; then + source "${__PROMPT_COLORS_SH}" # outsource the color defs + else + echo 1>&2 "Cannot find prompt-colors.sh!" + fi + fi # source the user's ~/.git-prompt-colors.sh file, or the one that should be # sitting in the same directory as this script - if [[ -z "$__GIT_PROMPT_COLORS_FILE" ]]; then - local pfx file dir - for dir in "$HOME" "$__GIT_PROMPT_DIR" ; do - for pfx in '.' '' ; do - file="$dir/${pfx}git-prompt-colors.sh" - if [[ -f "$file" ]]; then - __GIT_PROMPT_COLORS_FILE="$file" - break 2 - fi - done - done - fi - # if the envar is defined, source the file for custom colors - if [[ -n "$__GIT_PROMPT_COLORS_FILE" && -f "$__GIT_PROMPT_COLORS_FILE" ]]; then - source "$__GIT_PROMPT_COLORS_FILE" - else - # Default values for the appearance of the prompt. Do not change these - # below. Instead, copy these to `~/.git-prompt-colors.sh` and change them - # there. - GIT_PROMPT_PREFIX="[" - GIT_PROMPT_SUFFIX="]" - GIT_PROMPT_SEPARATOR="|" - GIT_PROMPT_BRANCH="${Magenta}" - GIT_PROMPT_STAGED="${Red}●" - GIT_PROMPT_CONFLICTS="${Red}✖" - GIT_PROMPT_CHANGED="${Blue}✚" - GIT_PROMPT_REMOTE=" " - GIT_PROMPT_UNTRACKED="${Cyan}…" - GIT_PROMPT_STASHED="${BoldBlue}⚑" - GIT_PROMPT_CLEAN="${BoldGreen}✔" + if gp_set_file_var __GIT_PROMPT_COLORS_FILE git-prompt-colors.sh ; then + + # if the envar is defined, source the file for custom colors + if [[ -n "${__GIT_PROMPT_COLORS_FILE}" ]]; then + source "${__GIT_PROMPT_COLORS_FILE}" + else + echo 1>&2 "Cannot find git-prompt-colors.sh!" + fi fi - # Various variables you might want for your PS1 prompt instead - local Time12a="\$(date +%H:%M)" - # local Time12a="(\$(date +%H:%M:%S))" - # local Time12a="(\@))" - local PathShort="\w" + # Do this only once to define PROMPT_START and PROMPT_END - if [ "x${GIT_PROMPT_START}" == "x" ]; then - PROMPT_START="${Yellow}${PathShort}${ResetColor}" - else - PROMPT_START="${GIT_PROMPT_START}" - fi + if [[ -z "$PROMPT_START" || -z "$PROMPT_END" ]]; then - if [ "x${GIT_PROMPT_END}" == "x" ]; then - PROMPT_END=" \n${White}${Time12a}${ResetColor} $ " - else - PROMPT_END="${GIT_PROMPT_END}" + # Various variables you might want for your PS1 prompt instead + local Time12a="\$(date +%H:%M)" + # local Time12a="(\$(date +%H:%M:%S))" + # local Time12a="(\@))" + local PathShort="\w" + + if [[ -z "${GIT_PROMPT_START}" ]] ; then + PROMPT_START="${Yellow}${PathShort}${ResetColor}" + else + PROMPT_START="${GIT_PROMPT_START}" + fi + + if [[ -z "${GIT_PROMPT_END}" ]] ; then + PROMPT_END=" \n${White}${Time12a}${ResetColor} $ " + else + PROMPT_END="${GIT_PROMPT_END}" + fi fi EMPTY_PROMPT="${PROMPT_START}$($prompt_callback)${PROMPT_END}" # fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes GIT_PROMPT_FETCH_TIMEOUT=${1-5} - if [ "x$__GIT_STATUS_CMD" == "x" ] - then + if [[ -z "$__GIT_STATUS_CMD" ]] ; then # if GIT_STATUS_CMD not defined.. git_prompt_dir local sfx file # look first for a '.sh' version, then use the python version for sfx in sh py ; do - file="${__GIT_PROMPT_DIR}/gitstatus.$sfx" + file="$__GIT_PROMPT_DIR/gitstatus.$sfx" if [[ -x "$file" ]]; then __GIT_STATUS_CMD="$file" break @@ -151,23 +166,9 @@ function checkUpstream() { } function updatePrompt() { - local GIT_PROMPT_PREFIX - local GIT_PROMPT_SUFFIX - local GIT_PROMPT_SEPARATOR - local GIT_PROMPT_BRANCH - local GIT_PROMPT_STAGED - local GIT_PROMPT_CONFLICTS - local GIT_PROMPT_CHANGED - local GIT_PROMPT_REMOTE - local GIT_PROMPT_UNTRACKED - local GIT_PROMPT_STASHED - local GIT_PROMPT_CLEAN local PROMPT_START local PROMPT_END local EMPTY_PROMPT - local ResetColor - local Blue - local GIT_PROMPT_FETCH_TIMEOUT local __GIT_STATUS_CMD git_prompt_config @@ -190,37 +191,43 @@ function updatePrompt() { if [[ -n "${GitStatus}" ]]; then local STATUS=" ${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}${GIT_BRANCH}${ResetColor}" - if [[ -n "${GIT_REMOTE}" ]]; then - STATUS="${STATUS}${GIT_PROMPT_REMOTE}${GIT_REMOTE}${ResetColor}" - fi - - STATUS="${STATUS}${GIT_PROMPT_SEPARATOR}" - if [ "${GIT_STAGED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_STAGED}${GIT_STAGED}${ResetColor}" - fi - - if [ "${GIT_CONFLICTS}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_CONFLICTS}${GIT_CONFLICTS}${ResetColor}" - fi - - if [ "${GIT_CHANGED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_CHANGED}${GIT_CHANGED}${ResetColor}" - fi - - if [ "${GIT_UNTRACKED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_UNTRACKED}${GIT_UNTRACKED}${ResetColor}" - fi - - if [ "${GIT_STASHED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_STASHED}${GIT_STASHED}${ResetColor}" - fi - - if [ "${GIT_CLEAN}" -eq "1" ]; then - STATUS="${STATUS}${GIT_PROMPT_CLEAN}" - fi - - STATUS="${STATUS}${ResetColor}${GIT_PROMPT_SUFFIX}" + # __add_status KIND VALEXPR INSERT + # eg: __add_status 'STAGED' '-ne 0' + __chk_gitvar_status() { + local v + if [[ "x$2" == "x-n" ]] ; then + v="$2 \"\${GIT_$1}\"" + else + v="\${GIT_$1} $2" + fi + if eval "test $v" ; then + if [[ $# -lt 2 || "$3" != '-' ]]; then + __add_status "\${GIT_PROMPT_$1}\${GIT_$1}\${ResetColor}" + else + __add_status "\${GIT_PROMPT_$1}\${ResetColor}" + fi + fi + } + + __add_gitvar_status() { + __add_status "\${GIT_PROMPT_$1}\${GIT_$1}\${ResetColor}" + } + + # __add_status SOMETEXT + __add_status() { + eval "STATUS=\"${STATUS}$1\"" + } + + __chk_gitvar_status 'REMOTE' '-n' + __add_status "$GIT_PROMPT_SEPARATOR" + __chk_gitvar_status 'STAGED' '-ne 0' + __chk_gitvar_status 'CONFLICTS' '-ne 0' + __chk_gitvar_status 'CHANGED' '-ne 0' + __chk_gitvar_status 'UNTRACKED' '-ne 0' + __chk_gitvar_status 'STASHED' '-ne 0' + __chk_gitvar_status 'CLEAN' '-eq 1' - + __add_status "${ResetColor}$GIT_PROMPT_SUFFIX" PS1="${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}" if [[ -n "${VIRTUAL_ENV}" ]]; then From f4b7cb3befdd7724a831188fc8cb30588d3ae11a Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 00:29:20 -0700 Subject: [PATCH 13/99] aks: added space after the flags to improve readability --- git-prompt-help.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) mode change 100644 => 100755 git-prompt-help.sh diff --git a/git-prompt-help.sh b/git-prompt-help.sh old mode 100644 new mode 100755 index ca6c5de..791bc7f --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -3,6 +3,8 @@ # being displayed. git_prompt_help() { + source prompt-colors.sh + source git-prompt-colors.sh cat <|] @@ -18,12 +20,12 @@ remote branch. It can be empty, or one of: LOCALSTATUS is one of the following: - ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean - ${GIT_PROMPT_STAGED}N${ResetColor} - N staged files - ${GIT_PROMPT_CONFLICTS}N${ResetColor} - N conflicted files - ${GIT_PROMPT_CHANGED}N${ResetColor} - N changed but *unstaged* files - ${GIT_PROMPT_UNTRACKED}N${ResetColor} - N untracked files - ${GIT_PROMPT_STASHED}N${ResetColor} - N stash entries + ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean + ${GIT_PROMPT_STAGED} N${ResetColor} - N staged files + ${GIT_PROMPT_CONFLICTS} N${ResetColor} - N conflicted files + ${GIT_PROMPT_CHANGED} N${ResetColor} - N changed but *unstaged* files + ${GIT_PROMPT_UNTRACKED} N${ResetColor} - N untracked files + ${GIT_PROMPT_STASHED} N${ResetColor} - N stash entries See "git_prompt_examples" for examples. EOF From 76dcf8b530e047ec5be068af048cb731c7885d98 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 00:39:16 -0700 Subject: [PATCH 14/99] aks: updated README.md --- README.md | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6c899e8..59c2fe7 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ staged, changed, etc. (an original idea from this [blog post][]). -`gitstatus.sh` added by [AKS](http://github.com/aks). +`gitstatus.sh` and `git-prompt-help.sh` added by [AKS](http://github.com/aks). ## Examples -The prompt may look like the following: +The prompt may look like the following: ![Example prompt](gitprompt.png) @@ -49,27 +49,32 @@ The symbols are as follows: ## Install -1. Clone this repository to your homedir - e.g. ``git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt`` -2. Source the file ``gitprompt.sh`` from your ``~/.bashrc`` config file -3. Go in a git repository and test it! +1. Clone this repository to your home directory. + + git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt + +2. Source the file `gitprompt.sh` from `~/.bashrc` + +3. `cd` to a git repository and test it! ## Configuration -1. You can use ``GIT_PROMPT_START`` and ``GIT_PROMPT_END`` to tweak your prompt +1. You can define `GIT_PROMPT_START` and `GIT_PROMPT_END` to tweak your prompt. -2. The default colors are defined within ``gitprompt.sh``, but may be - overridden by copying ``git-prompt-colors.sh`` to your home directory at - ``~/.git-prompt-colors.sh``. This file may also be found in the same - directory as ``gitprompt.sh``, but without the leading ``.``. +2. 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 + `git-prompt-colors.sh`. 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. 3. The current git repo information is obtained by the script `gitstatus.sh` or `gitstatus.py`. Both scripts do the same thing, but the bash script is a tad more quick, and is used by default. If you prefer the python script (possibly because you have enhanced it), simply delete or change the name of - ``gitstatus.sh``. + `gitstatus.sh`. -4. You can define ``prompt_callback`` function to tweak your prompt dynamically. +4. You can define `prompt_callback` function to tweak your prompt dynamically. ```sh function prompt_callback { From 1030f78f48493fc57e19c352a5ebd19e14a5343d Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Fri, 24 Jan 2014 10:09:15 -0800 Subject: [PATCH 15/99] aks:testing new file in local, but not in remote --- newfile.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newfile.txt diff --git a/newfile.txt b/newfile.txt new file mode 100644 index 0000000..e69de29 From eb2554395c43287c1ada1544012106b61f8ce3c8 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 00:19:32 -0700 Subject: [PATCH 16/99] aks: refactor prompt color names & generation into separate file --- prompt-colors.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 prompt-colors.sh diff --git a/prompt-colors.sh b/prompt-colors.sh new file mode 100644 index 0000000..9249a7e --- /dev/null +++ b/prompt-colors.sh @@ -0,0 +1,82 @@ +# prompt-colors.sh +# +# source this file to get color definitions +# if $debug or $verbose is set, the definitions +# are also printed to STDERR. + +define_color_names() { + + ColorNames=( Black Red Green Yellow Blue Magneta Cyan White ) + FgColors=( 30 31 32 33 34 35 36 37 ) + BgColors=( 40 41 42 43 44 45 46 47 ) + + local AttrNorm=0 + local AttrBright=1 + local AttrDim=2 + local AttrUnder=4 + local AttrBlink=5 + local AttrRev=7 + local AttrHide=8 + + # define "BoldCOLOR", "BrightCOLOR", and "DimCOLOR" names + + # _map_colors ATTRNAME ATTRVALUE + # + # Defines three names for every color, attribute combintaion: + # {ATTRNAME}{COLORNAME} + # {ATTRNAME}{COLORNAME}Fg + # {ATTRNAME}{COLORNAME}Bg + # + # Example: BoldRed, BoldRedFg, BoldRedBg + + _map_colors() { + local x=0 + local attrname="$1" + local attrcode=$2 + while (( x < 8 )) ; do + local colorname=${ColorNames[x]} + local fgcolorcode=${FgColors[x]} + local bgcolorcode=${BgColors[x]} + longcolorname="${attrname}${colorname}" + _def_color $longcolorname $attrcode $fgcolorcode + _def_color ${longcolorname}Fg $attrcode $fgcolorcode + _def_color ${longcolorname}Bg $attrcode $bgcolorcode + (( x++ )) + done + } + + # _term_color [ N | N M ] + _term_color() { + local cv + if (( $# > 1 )); then + cv="${1};${2}" + else + cv="${1}" + fi + echo "\[\033[${cv}m\]" + } + + # def_color NAME ATTRCODE COLORCODE + _def_color() { + local def="$1=\"\`_term_color $2 $3\`\"" + if [[ -n "$debug$verbose" ]]; then + echo 1>&2 "+ $def" + fi + eval "$def" + } + + #ResetColor="`_term_color 0`" # Text reset + + _map_colors Bold $AttrBright + _map_colors Bright $AttrBright + _map_colors Dim $AttrDim + _map_colors '' $AttrNorm + + _def_color IntenseBlack 0 90 + _def_color ResetColor 0 0 + +} +define_color_names + +# end of prompt-colors.sh +# vim: set ai sw=2 From 4ecaa1e645c5e426fe8c4825eed2ee6d689f2f3b Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 00:20:00 -0700 Subject: [PATCH 17/99] aks: make the prompt vars all global --- git-prompt-colors.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index 73e10a8..aa76a49 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -1,3 +1,17 @@ +# These are the color definitions used by gitprompt.sh + +declare -g GIT_PROMPT_PREFIX +declare -g GIT_PROMPT_SUFFIX +declare -g GIT_PROMPT_SEPARATOR +declare -g GIT_PROMPT_BRANCH +declare -g GIT_PROMPT_STAGED +declare -g GIT_PROMPT_CONFLICTS +declare -g GIT_PROMPT_CHANGED +declare -g GIT_PROMPT_REMOTE +declare -g GIT_PROMPT_UNTRACKED +declare -g GIT_PROMPT_STASHED +declare -g GIT_PROMPT_CLEAN + local Time12a="\$(date +%H:%M)" local PathShort="\w" @@ -8,12 +22,12 @@ GIT_PROMPT_SEPARATOR="|" # separates each item GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory 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_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) and the symbols for ahead and behind GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs -GIT_PROMPT_STASHED="${BoldBlue}⚑" # the number of stashed files/dir +GIT_PROMPT_STASHED="${BoldBlue}⚑ " # the number of stashed files/dir GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 @@ -27,4 +41,4 @@ GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " # 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 \ No newline at end of file +GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found From 3ee76282d7fca6ae40fe6a1e11b303bfb829ca0e Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 00:21:28 -0700 Subject: [PATCH 18/99] aks: major rewrite with refactored colors, envar management --- gitprompt.sh | 261 +++++++++++++++++++++++---------------------------- 1 file changed, 120 insertions(+), 141 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 262bec1..1dab935 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -22,115 +22,106 @@ function git_prompt_dir() fi } -function git_prompt_config() -{ - # Colors - ResetColor="\[\033[0m\]" # Text reset - - # Bold - local BoldGreen="\[\033[1;32m\]" # Green - local BoldBlue="\[\033[1;34m\]" # Blue - - # High Intensty - local IntenseBlack="\[\033[0;90m\]" # Grey +# gp_set_file_var ENVAR SOMEFILE +# +# Set ENVAR to the path to SOMEFILE, based on $HOME, $__GIT_PROMPT_DIR, and the +# directory of the current script. The SOMEFILE can be prefixed with '.', or +# not. +# +# Return 0 (success) if ENVAR not already defined, 1 (failure) otherwise. + +function gp_set_file_var() { + local envar="$1" + local file="$2" + if eval "test -z \"\$$envar\"" ; then + eval "$envar=" # set empty envar + gp_maybe_set_envar_to_path "$envar" "$HOME/.$file" "$HOME/$file" "$HOME/lib/$file" && return 0 + git_prompt_dir + gp_maybe_set_envar_to_path "$envar" "$__GIT_PROMPT_DIR/$file" "${0##*/}/$file" && return 0 + fi + return 1 +} - # Bold High Intensty - local Magenta="\[\033[1;95m\]" # Purple +# gp_maybe_set_envar_to_path ENVAR FILEPATH ... +# +# return 0 (true) if any FILEPATH is readable, set ENVAR to it +# return 1 (false) if not + +function gp_maybe_set_envar_to_path(){ + local envar="$1" + shift + local file + for file in "$@" ; do + if [[ -r "$file" ]]; then + eval "$envar=\"$file\"" + return 0 + fi + done + return 1 +} - # Regular Colors - local Yellow="\[\033[0;33m\]" - local White='\[\033[37m\]' - local Red="\[\033[0;31m\]" - local Blue="\[\033[0;34m\]" - local Cyan="\[\033[0;36m\]" - local Green="\[\033[0;32m\]" +function git_prompt_config() +{ #Checking if root to change output _isroot=false [[ $UID -eq 0 ]] && _isroot=true + # There are two files related to colors: + # + # prompt-colors.sh -- sets generic color names suitable for bash `PS1` prompt + # git-prompt-colors.sh -- sets the GIT_PROMPT color scheme, using names from prompt-colors.sh + + if gp_set_file_var __PROMPT_COLORS_SH prompt-colors.sh ; then + if [[ -n "${__PROMPT_COLORS_SH}" ]]; then + source "${__PROMPT_COLORS_SH}" # outsource the color defs + else + echo 1>&2 "Cannot find prompt-colors.sh!" + fi + fi + # source the user's ~/.git-prompt-colors.sh file, or the one that should be # sitting in the same directory as this script - if [[ -z "$__GIT_PROMPT_COLORS_FILE" ]]; then - local pfx file dir - for dir in "$HOME" "$__GIT_PROMPT_DIR" ; do - for pfx in '.' '' ; do - file="$dir/${pfx}git-prompt-colors.sh" - if [[ -f "$file" ]]; then - __GIT_PROMPT_COLORS_FILE="$file" - break 2 - fi - done - done + if gp_set_file_var __GIT_PROMPT_COLORS_FILE git-prompt-colors.sh ; then + + # if the envar is defined, source the file for custom colors + if [[ -n "${__GIT_PROMPT_COLORS_FILE}" ]]; then + source "${__GIT_PROMPT_COLORS_FILE}" + else + echo 1>&2 "Cannot find git-prompt-colors.sh!" + fi fi - # Various variables you might want for your PS1 prompt instead - local Time12a="\$(date +%H:%M)" - # local Time12a="(\$(date +%H:%M:%S))" - # local Time12a="(\@))" - local PathShort="\w" + # Do this only once to define PROMPT_START and PROMPT_END - # if the envar is defined, source the file for custom colors - if [[ -n "$__GIT_PROMPT_COLORS_FILE" && -f "$__GIT_PROMPT_COLORS_FILE" ]]; then - source "$__GIT_PROMPT_COLORS_FILE" - else - # Default values for the appearance of the prompt. Do not change these - # below. Instead, copy these to `~/.git-prompt-colors.sh` and change them - # there. - GIT_PROMPT_PREFIX="[" - GIT_PROMPT_SUFFIX="]" - GIT_PROMPT_SEPARATOR="|" - GIT_PROMPT_BRANCH="${Magenta}" - GIT_PROMPT_STAGED="${Red}●" - GIT_PROMPT_CONFLICTS="${Red}✖" - GIT_PROMPT_CHANGED="${Blue}✚" - GIT_PROMPT_REMOTE=" " - GIT_PROMPT_UNTRACKED="${Cyan}…" - GIT_PROMPT_STASHED="${BoldBlue}⚑" - GIT_PROMPT_CLEAN="${BoldGreen}✔" - GIT_PROMPT_COMMAND_OK="${Green}✔ " - GIT_PROMPT_COMMAND_FAIL="${Red}✘ " - - GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " - GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " - - # Please do not add colors to these symbols - GIT_PROMPT_SYMBOLS_AHEAD="↑·" - GIT_PROMPT_SYMBOLS_BEHIND="↓·" - GIT_PROMPT_SYMBOLS_PREHASH=":" - fi + if [[ -z "$PROMPT_START" || -z "$PROMPT_END" ]]; then - if [ "x${GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR}" == "x1" ]; then - if [ $LAST_COMMAND_STATE = 0 ]; then - LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_OK}"; - else - LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_FAIL}"; - fi - fi + # Various variables you might want for your PS1 prompt instead + local Time12a="\$(date +%H:%M)" + # local Time12a="(\$(date +%H:%M:%S))" + # local Time12a="(\@))" + local PathShort="\w" - if [ "x${GIT_PROMPT_START}" == "x" ]; then - #First statment is for non root behavior second for root - if $_isroot; then - PROMPT_START="${GIT_PROMPT_START_ROOT}" + if [[ -z "${GIT_PROMPT_START}" ]] ; then + if $_isroot; then + PROMPT_START="$GIT_PROMPT_START_ROOT" + else + PROMPT_START="$GIT_PROMPT_START_USER" + fi else - PROMPT_START="${GIT_PROMPT_START_USER}" + PROMPT_START="${GIT_PROMPT_START}" fi - else - PROMPT_START="${GIT_PROMPT_START}" - fi - if [ "x${GIT_PROMPT_END}" == "x" ]; then - #First statment is for non root behavior second for root - if ! $_isroot; then - PROMPT_END="${GIT_PROMPT_END_USER}" + if [[ -z "${GIT_PROMPT_END}" ]] ; then + if $_isroot; then + PROMPT_END="$GIT_PROMPT_END_ROOT" + else + PROMPT_END="$GIT_PROMPT_END_USER" + fi else - PROMPT_END="${GIT_PROMPT_END_ROOT}" + PROMPT_END="${GIT_PROMPT_END}" fi - else - PROMPT_END="${GIT_PROMPT_END}" fi # set GIT_PROMPT_LEADING_SPACE to 0 if you want to have no leading space in front of the GIT prompt @@ -154,18 +145,11 @@ function git_prompt_config() # fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes GIT_PROMPT_FETCH_TIMEOUT=${1-5} - if [ "x$__GIT_STATUS_CMD" == "x" ] - then + if [[ -z "$__GIT_STATUS_CMD" ]] ; then # if GIT_STATUS_CMD not defined.. git_prompt_dir - local sfx file - # look first for a '.sh' version, then use the python version - for sfx in sh py ; do - file="${__GIT_PROMPT_DIR}/gitstatus.$sfx" - if [[ -x "$file" ]]; then - __GIT_STATUS_CMD="$file" - break - fi - done + if ! gp_maybe_set_envar_to_path __GIT_STATUS_CMD "$__GIT_PROMPT_DIR/gitstatus.sh" "$__GIT_PROMPT_DIR/gitstatus.py" ; then + echo 1>&2 "Cannot find gitstatus.sh or gitstatus.py!" + fi fi } @@ -217,17 +201,6 @@ function checkUpstream() { } function updatePrompt() { - local GIT_PROMPT_PREFIX - local GIT_PROMPT_SUFFIX - local GIT_PROMPT_SEPARATOR - local GIT_PROMPT_BRANCH - local GIT_PROMPT_STAGED - local GIT_PROMPT_CONFLICTS - local GIT_PROMPT_CHANGED - local GIT_PROMPT_REMOTE - local GIT_PROMPT_UNTRACKED - local GIT_PROMPT_STASHED - local GIT_PROMPT_CLEAN local LAST_COMMAND_INDICATOR local PROMPT_LEADING_SPACE local PROMPT_START @@ -257,37 +230,43 @@ function updatePrompt() { if [[ -n "${GitStatus}" ]]; then local STATUS="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}${GIT_BRANCH}${ResetColor}" - if [[ -n "${GIT_REMOTE}" ]]; then - STATUS="${STATUS}${GIT_PROMPT_REMOTE}${GIT_REMOTE}${ResetColor}" - fi - - STATUS="${STATUS}${GIT_PROMPT_SEPARATOR}" - if [ "${GIT_STAGED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_STAGED}${GIT_STAGED}${ResetColor}" - fi - - if [ "${GIT_CONFLICTS}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_CONFLICTS}${GIT_CONFLICTS}${ResetColor}" - fi - - if [ "${GIT_CHANGED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_CHANGED}${GIT_CHANGED}${ResetColor}" - fi - - if [ "${GIT_UNTRACKED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_UNTRACKED}${GIT_UNTRACKED}${ResetColor}" - fi - - if [ "${GIT_STASHED}" -ne "0" ]; then - STATUS="${STATUS}${GIT_PROMPT_STASHED}${GIT_STASHED}${ResetColor}" - fi - - if [ "${GIT_CLEAN}" -eq "1" ]; then - STATUS="${STATUS}${GIT_PROMPT_CLEAN}" - fi - - STATUS="${STATUS}${ResetColor}${GIT_PROMPT_SUFFIX}" + # __add_status KIND VALEXPR INSERT + # eg: __add_status 'STAGED' '-ne 0' + __chk_gitvar_status() { + local v + if [[ "x$2" == "x-n" ]] ; then + v="$2 \"\${GIT_$1}\"" + else + v="\${GIT_$1} $2" + fi + if eval "test $v" ; then + if [[ $# -lt 2 || "$3" != '-' ]]; then + __add_status "\${GIT_PROMPT_$1}\${GIT_$1}\${ResetColor}" + else + __add_status "\${GIT_PROMPT_$1}\${ResetColor}" + fi + fi + } + + __add_gitvar_status() { + __add_status "\${GIT_PROMPT_$1}\${GIT_$1}\${ResetColor}" + } + + # __add_status SOMETEXT + __add_status() { + eval "STATUS=\"${STATUS}$1\"" + } + + __chk_gitvar_status 'REMOTE' '-n' + __add_status "$GIT_PROMPT_SEPARATOR" + __chk_gitvar_status 'STAGED' '-ne 0' + __chk_gitvar_status 'CONFLICTS' '-ne 0' + __chk_gitvar_status 'CHANGED' '-ne 0' + __chk_gitvar_status 'UNTRACKED' '-ne 0' + __chk_gitvar_status 'STASHED' '-ne 0' + __chk_gitvar_status 'CLEAN' '-eq 1' - + __add_status "${ResetColor}$GIT_PROMPT_SUFFIX" PS1="${LAST_COMMAND_INDICATOR}${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}" if [[ -n "${VIRTUAL_ENV}" ]]; then From 1076fb95385643fa8dfbcd919da6ed5ba22d214d Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 00:29:20 -0700 Subject: [PATCH 19/99] aks: added space after the flags to improve readability --- git-prompt-help.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) mode change 100644 => 100755 git-prompt-help.sh diff --git a/git-prompt-help.sh b/git-prompt-help.sh old mode 100644 new mode 100755 index ca6c5de..791bc7f --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -3,6 +3,8 @@ # being displayed. git_prompt_help() { + source prompt-colors.sh + source git-prompt-colors.sh cat <|] @@ -18,12 +20,12 @@ remote branch. It can be empty, or one of: LOCALSTATUS is one of the following: - ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean - ${GIT_PROMPT_STAGED}N${ResetColor} - N staged files - ${GIT_PROMPT_CONFLICTS}N${ResetColor} - N conflicted files - ${GIT_PROMPT_CHANGED}N${ResetColor} - N changed but *unstaged* files - ${GIT_PROMPT_UNTRACKED}N${ResetColor} - N untracked files - ${GIT_PROMPT_STASHED}N${ResetColor} - N stash entries + ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean + ${GIT_PROMPT_STAGED} N${ResetColor} - N staged files + ${GIT_PROMPT_CONFLICTS} N${ResetColor} - N conflicted files + ${GIT_PROMPT_CHANGED} N${ResetColor} - N changed but *unstaged* files + ${GIT_PROMPT_UNTRACKED} N${ResetColor} - N untracked files + ${GIT_PROMPT_STASHED} N${ResetColor} - N stash entries See "git_prompt_examples" for examples. EOF From 7063695c86dde42f5c87a268ba83f817b534213f Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 00:39:16 -0700 Subject: [PATCH 20/99] aks: updated README.md --- README.md | 65 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 5c7f5b1..7f8131b 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ staged, changed, etc. (an original idea from this [blog post][]). -`gitstatus.sh` added by [AKS](http://github.com/aks). +`gitstatus.sh` and `git-prompt-help.sh` added by [AKS](http://github.com/aks). ## Examples -The prompt may look like the following: +The prompt may look like the following: ![Example prompt](gitprompt.png) @@ -49,9 +49,13 @@ The symbols are as follows: ## Install -- Clone this repository to your homedir - e.g. ``git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt`` -- Source the file ``gitprompt.sh`` from your ``~/.bashrc`` config file: +1. Clone this repository to your home directory. + + git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt + +2. Source the file `gitprompt.sh` from `~/.bashrc` + +3. `cd` to a git repository and test it! ```sh # some other config in .bashrc @@ -61,28 +65,40 @@ The symbols are as follows: # Set config variables first GIT_PROMPT_ONLY_IN_REPO=1 + # GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status + + # 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 source ~/.bash-git-prompt/gitprompt.sh ``` - Go in a git repository and test it! -## Configuration +- You can define `GIT_PROMPT_START` and `GIT_PROMPT_END` to tweak your prompt. -- The default colors and some variables for tweaking the prompt are defined - within ``gitprompt.sh``, but may be overridden by copying ``git-prompt-colors.sh`` - to your home directory at ``~/.git-prompt-colors.sh``. This file may also be found in the same - directory as ``gitprompt.sh``, but without the leading ``.``. +- 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 + `git-prompt-colors.sh`. 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`` +- 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` or - `gitstatus.py`. Both scripts do the same thing, but the bash script is a - tad more quick, and is used by default. If you prefer the python script - (possibly because you have enhanced it), simply delete or change the name of - ``gitstatus.sh``. + `gitstatus.py`. Both scripts do the same thing, but the bash script is a tad + more quick, and is used by default. If you prefer the python script + (possibly because you have enhanced it), simply delete or change the name of + `gitstatus.sh`. + +- You can define `prompt_callback` function to tweak your prompt dynamically. -- You can define ``prompt_callback`` function to tweak your prompt dynamically. ```sh function prompt_callback { if [ `jobs | wc -l` -ne 0 ]; then @@ -91,19 +107,26 @@ function prompt_callback { } ``` -- 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 +- 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 additional indicator at the start of the prompt, which shows the result of the last executed command by setting ``GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1`` before sourcing the gitprompt script +- You can show an additional indicator at the start of the prompt, which shows + the result of the last executed command by setting + ``GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1`` before sourcing the gitprompt + script -- 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. +- 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 get help on the git prompt with the function ``git_prompt_help``. - Examples are available with ``git_prompt_examples``. + Examples are available with ``git_prompt_examples``. **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: From 839de0333fb6d8ae80ea6197872872da74b30782 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 28 Aug 2014 19:44:46 +0200 Subject: [PATCH 21/99] Readied overwritten function for displaying the last command indicator --- gitprompt.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gitprompt.sh b/gitprompt.sh index 1dab935..50863d0 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -93,6 +93,14 @@ function git_prompt_config() fi fi + if [ "x${GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR}" == "x1" ]; then + if [ $LAST_COMMAND_STATE = 0 ]; then + LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_OK}"; + else + LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_FAIL}"; + fi + fi + # Do this only once to define PROMPT_START and PROMPT_END if [[ -z "$PROMPT_START" || -z "$PROMPT_END" ]]; then From 3ab4973b867951b141137c18a5925b40f810c5f2 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 11:39:24 -0700 Subject: [PATCH 22/99] aks: only define the colors once --- git-prompt-colors.sh | 78 +++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index aa76a49..654fb1e 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -1,44 +1,40 @@ # These are the color definitions used by gitprompt.sh -declare -g GIT_PROMPT_PREFIX -declare -g GIT_PROMPT_SUFFIX -declare -g GIT_PROMPT_SEPARATOR -declare -g GIT_PROMPT_BRANCH -declare -g GIT_PROMPT_STAGED -declare -g GIT_PROMPT_CONFLICTS -declare -g GIT_PROMPT_CHANGED -declare -g GIT_PROMPT_REMOTE -declare -g GIT_PROMPT_UNTRACKED -declare -g GIT_PROMPT_STASHED -declare -g GIT_PROMPT_CLEAN - -local Time12a="\$(date +%H:%M)" -local PathShort="\w" +define_git_prompt_colors() { + + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + 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) and the symbols for ahead and behind + 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_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + # 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 +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi -# These are the color definitions used by gitprompt.sh -GIT_PROMPT_PREFIX="[" # start of the git info string -GIT_PROMPT_SUFFIX="]" # the end of the git info string -GIT_PROMPT_SEPARATOR="|" # separates each item - -GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory -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) and the symbols for ahead and behind -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_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 -GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 - -GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" -GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}" -GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " -GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " - -# 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 From 7bf6b96b7136fe5f439a6a543b0a9a62d1d27d5e Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 11:39:42 -0700 Subject: [PATCH 23/99] aks: only define the colors once --- prompt-colors.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/prompt-colors.sh b/prompt-colors.sh index 9249a7e..cacf7bb 100644 --- a/prompt-colors.sh +++ b/prompt-colors.sh @@ -76,7 +76,11 @@ define_color_names() { _def_color ResetColor 0 0 } -define_color_names + +# do the color definitions only once +if [[ ${#ColorNames[*]} = 0 || -z "$IntenseBlack" || -z "$ResetColor" ]]; then + define_color_names +fi # end of prompt-colors.sh # vim: set ai sw=2 From a9cd7f330ccae0dd1e654b85f4934daa1bd27225 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 11:41:12 -0700 Subject: [PATCH 24/99] aks: optimzations; don't lookup the same files over and over --- gitprompt.sh | 68 +++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 1dab935..7242fdc 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -24,6 +24,7 @@ function git_prompt_dir() # gp_set_file_var ENVAR SOMEFILE # +# If ENVAR is set, check that it's value exists as a readable file. Otherwise, # Set ENVAR to the path to SOMEFILE, based on $HOME, $__GIT_PROMPT_DIR, and the # directory of the current script. The SOMEFILE can be prefixed with '.', or # not. @@ -33,7 +34,13 @@ function git_prompt_dir() function gp_set_file_var() { local envar="$1" local file="$2" - if eval "test -z \"\$$envar\"" ; then + if eval "[[ -n \"\$$envar\" && -r \"\$$envar\" ]]" ; then # is envar set to a readable file? + local basefile + eval "basefile=\"\`basename \\\"\$$envar\\\"\`\"" # assign basefile + if [[ "$basefile" = "$file" || "$basefile" = ".$file" ]]; then + return 0 + fi + else # envar is not set, or it's set to a different file than requested eval "$envar=" # set empty envar gp_maybe_set_envar_to_path "$envar" "$HOME/.$file" "$HOME/$file" "$HOME/lib/$file" && return 0 git_prompt_dir @@ -73,24 +80,18 @@ function git_prompt_config() # git-prompt-colors.sh -- sets the GIT_PROMPT color scheme, using names from prompt-colors.sh if gp_set_file_var __PROMPT_COLORS_SH prompt-colors.sh ; then - if [[ -n "${__PROMPT_COLORS_SH}" ]]; then - source "${__PROMPT_COLORS_SH}" # outsource the color defs - else - echo 1>&2 "Cannot find prompt-colors.sh!" - fi + source "${__PROMPT_COLORS_SH}" # outsource the color defs + else + echo 1>&2 "Cannot find prompt-colors.sh!" fi # source the user's ~/.git-prompt-colors.sh file, or the one that should be # sitting in the same directory as this script if gp_set_file_var __GIT_PROMPT_COLORS_FILE git-prompt-colors.sh ; then - - # if the envar is defined, source the file for custom colors - if [[ -n "${__GIT_PROMPT_COLORS_FILE}" ]]; then - source "${__GIT_PROMPT_COLORS_FILE}" - else - echo 1>&2 "Cannot find git-prompt-colors.sh!" - fi + source "${__GIT_PROMPT_COLORS_FILE}" + else + echo 1>&2 "Cannot find git-prompt-colors.sh!" fi # Do this only once to define PROMPT_START and PROMPT_END @@ -110,7 +111,7 @@ function git_prompt_config() PROMPT_START="$GIT_PROMPT_START_USER" fi else - PROMPT_START="${GIT_PROMPT_START}" + PROMPT_START="$GIT_PROMPT_START" fi if [[ -z "${GIT_PROMPT_END}" ]] ; then @@ -120,27 +121,27 @@ function git_prompt_config() PROMPT_END="$GIT_PROMPT_END_USER" fi else - PROMPT_END="${GIT_PROMPT_END}" + PROMPT_END="$GIT_PROMPT_END" fi fi # set GIT_PROMPT_LEADING_SPACE to 0 if you want to have no leading space in front of the GIT prompt - if [ "x${GIT_PROMPT_LEADING_SPACE}" == "x0" ]; then + if [[ "$GIT_PROMPT_LEADING_SPACE" = 0 ]]; then PROMPT_LEADING_SPACE="" else PROMPT_LEADING_SPACE=" " fi - if [ "x${GIT_PROMPT_ONLY_IN_REPO}" == "x1" ]; then - EMPTY_PROMPT=$OLD_GITPROMPT + if [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then + EMPTY_PROMPT="$OLD_GITPROMPT" else - if [[ -n "${VIRTUAL_ENV}" ]]; then - EMPTY_PROMPT="${LAST_COMMAND_INDICATOR}(${Blue}$(basename "${VIRTUAL_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}" + local ps="$LAST_COMMAND_INDICATOR" + if [[ -n "$VIRTUAL_ENV" ]]; then + ps="$ps(${Blue}$(basename \"${VIRTUAL_ENV}\")${ResetColor}) " elif [[ -n "${CONDA_DEFAULT_ENV}" ]]; then - EMPTY_PROMPT="${LAST_COMMAND_INDICATOR}(${Blue}$(basename "${CONDA_DEFAULT_ENV}")${ResetColor}) ${PROMPT_START}$($prompt_callback)${PROMPT_END}" - else - EMPTY_PROMPT="${LAST_COMMAND_INDICATOR}${PROMPT_START}$($prompt_callback)${PROMPT_END}" + ps="$ps(${Blue}$(basename \"${CONDA_DEFAULT_ENV}\")${ResetColor}) " fi + EMPTY_PROMPT="$ps${PROMPT_START}$($prompt_callback)${PROMPT_END}" fi # fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes @@ -150,6 +151,7 @@ function git_prompt_config() if ! gp_maybe_set_envar_to_path __GIT_STATUS_CMD "$__GIT_PROMPT_DIR/gitstatus.sh" "$__GIT_PROMPT_DIR/gitstatus.py" ; then echo 1>&2 "Cannot find gitstatus.sh or gitstatus.py!" fi + # __GIT_STATUS_CMD defined fi } @@ -163,21 +165,21 @@ function setGitPrompt() { local repo=`git rev-parse --show-toplevel 2> /dev/null` if [[ ! -e "${repo}" ]]; then - PS1="${EMPTY_PROMPT}" + PS1="$EMPTY_PROMPT" return fi local FETCH_REMOTE_STATUS=1 - if [[ "x${GIT_PROMPT_FETCH_REMOTE_STATUS}" == "x0" ]]; then + if [[ "$GIT_PROMPT_FETCH_REMOTE_STATUS" = 0 ]]; then FETCH_REMOTE_STATUS=0 fi - if [[ -e "${repo}/.bash-git-rc" ]]; then - source "${repo}/.bash-git-rc" + if [[ -e "$repo/.bash-git-rc" ]]; then + source "$repo/.bash-git-rc" fi - if [ "x${FETCH_REMOTE_STATUS}" == "x1" ]; then - checkUpstream + if [ "$FETCH_REMOTE_STATUS" = 1 ]; then + checkUpstream fi updatePrompt @@ -189,7 +191,7 @@ function checkUpstream() { local FETCH_HEAD="${repo}/.git/FETCH_HEAD" # Fech repo if local is stale for more than $GIT_FETCH_TIMEOUT minutes - if [[ ! -e "${FETCH_HEAD}" || -e `find "${FETCH_HEAD}" -mmin +${GIT_PROMPT_FETCH_TIMEOUT}` ]] + if [[ ! -e "$FETCH_HEAD" || -e `find "$FETCH_HEAD" -mmin +$GIT_PROMPT_FETCH_TIMEOUT` ]] then if [[ -n $(git remote show) ]]; then ( @@ -270,15 +272,15 @@ function updatePrompt() { PS1="${LAST_COMMAND_INDICATOR}${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}" if [[ -n "${VIRTUAL_ENV}" ]]; then - PS1="(${Blue}$(basename ${VIRTUAL_ENV})${ResetColor}) ${PS1}" + PS1="(${Blue}$(basename \"$VIRTUAL_ENV\")${ResetColor}) ${PS1}" fi if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then - PS1="(${Blue}$(basename ${CONDA_DEFAULT_ENV})${ResetColor}) ${PS1}" + PS1="(${Blue}$(basename \"$CONDA_DEFAULT_ENV\")${ResetColor}) ${PS1}" fi else - PS1="${EMPTY_PROMPT}" + PS1="$EMPTY_PROMPT" fi } From a3994cd962d89b90d48cc6acef94de22a857ab07 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 11:51:01 -0700 Subject: [PATCH 25/99] aks: aesthetic touchups --- gitprompt.sh | 60 ++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 7242fdc..5a1dd93 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -11,14 +11,14 @@ function git_prompt_dir() { # assume the gitstatus.py is in the same directory as this script # code thanks to http://stackoverflow.com/questions/59895 - if [ -z "${__GIT_PROMPT_DIR}" ]; then + if [ -z "$__GIT_PROMPT_DIR" ]; then local SOURCE="${BASH_SOURCE[0]}" - while [ -h "${SOURCE}" ]; do - local DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" - SOURCE="$(readlink "${SOURCE}")" - [[ $SOURCE != /* ]] && SOURCE="${DIR}/${SOURCE}" + while [ -h "$SOURCE" ]; do + local DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" done - __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" + __GIT_PROMPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" fi } @@ -80,7 +80,7 @@ function git_prompt_config() # git-prompt-colors.sh -- sets the GIT_PROMPT color scheme, using names from prompt-colors.sh if gp_set_file_var __PROMPT_COLORS_SH prompt-colors.sh ; then - source "${__PROMPT_COLORS_SH}" # outsource the color defs + source "$__PROMPT_COLORS_SH" # outsource the color defs else echo 1>&2 "Cannot find prompt-colors.sh!" fi @@ -89,7 +89,7 @@ function git_prompt_config() # sitting in the same directory as this script if gp_set_file_var __GIT_PROMPT_COLORS_FILE git-prompt-colors.sh ; then - source "${__GIT_PROMPT_COLORS_FILE}" + source "$__GIT_PROMPT_COLORS_FILE" else echo 1>&2 "Cannot find git-prompt-colors.sh!" fi @@ -104,7 +104,7 @@ function git_prompt_config() # local Time12a="(\@))" local PathShort="\w" - if [[ -z "${GIT_PROMPT_START}" ]] ; then + if [[ -z "$GIT_PROMPT_START" ]] ; then if $_isroot; then PROMPT_START="$GIT_PROMPT_START_ROOT" else @@ -114,7 +114,7 @@ function git_prompt_config() PROMPT_START="$GIT_PROMPT_START" fi - if [[ -z "${GIT_PROMPT_END}" ]] ; then + if [[ -z "$GIT_PROMPT_END" ]] ; then if $_isroot; then PROMPT_END="$GIT_PROMPT_END_ROOT" else @@ -137,11 +137,11 @@ function git_prompt_config() else local ps="$LAST_COMMAND_INDICATOR" if [[ -n "$VIRTUAL_ENV" ]]; then - ps="$ps(${Blue}$(basename \"${VIRTUAL_ENV}\")${ResetColor}) " - elif [[ -n "${CONDA_DEFAULT_ENV}" ]]; then - ps="$ps(${Blue}$(basename \"${CONDA_DEFAULT_ENV}\")${ResetColor}) " + ps="$ps($Blue$(basename \"$VIRTUAL_ENV\")$ResetColor) " + elif [[ -n "$CONDA_DEFAULT_ENV" ]]; then + ps="$ps($Blue$(basename \"$CONDA_DEFAULT_ENV\")$ResetColor) " fi - EMPTY_PROMPT="$ps${PROMPT_START}$($prompt_callback)${PROMPT_END}" + EMPTY_PROMPT="$ps$PROMPT_START$($prompt_callback)$PROMPT_END" fi # fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes @@ -164,7 +164,7 @@ function setGitPrompt() { git_prompt_config local repo=`git rev-parse --show-toplevel 2> /dev/null` - if [[ ! -e "${repo}" ]]; then + if [[ ! -e "$repo" ]]; then PS1="$EMPTY_PROMPT" return fi @@ -189,7 +189,7 @@ function checkUpstream() { local GIT_PROMPT_FETCH_TIMEOUT git_prompt_config - local FETCH_HEAD="${repo}/.git/FETCH_HEAD" + local FETCH_HEAD="$repo/.git/FETCH_HEAD" # Fech repo if local is stale for more than $GIT_FETCH_TIMEOUT minutes if [[ ! -e "$FETCH_HEAD" || -e `find "$FETCH_HEAD" -mmin +$GIT_PROMPT_FETCH_TIMEOUT` ]] then @@ -215,7 +215,7 @@ function updatePrompt() { git_prompt_config local -a GitStatus - GitStatus=($("${__GIT_STATUS_CMD}" 2>/dev/null)) + GitStatus=($("$__GIT_STATUS_CMD" 2>/dev/null)) local GIT_BRANCH=${GitStatus[0]} local GIT_REMOTE=${GitStatus[1]} @@ -229,7 +229,7 @@ function updatePrompt() { local GIT_STASHED=${GitStatus[6]} local GIT_CLEAN=${GitStatus[7]} - if [[ -n "${GitStatus}" ]]; then + if [[ -n "$GitStatus" ]]; then local STATUS="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}${GIT_BRANCH}${ResetColor}" # __add_status KIND VALEXPR INSERT @@ -238,26 +238,26 @@ function updatePrompt() { __chk_gitvar_status() { local v if [[ "x$2" == "x-n" ]] ; then - v="$2 \"\${GIT_$1}\"" + v="$2 \"\$GIT_$1\"" else - v="\${GIT_$1} $2" + v="\$GIT_$1 $2" fi if eval "test $v" ; then if [[ $# -lt 2 || "$3" != '-' ]]; then - __add_status "\${GIT_PROMPT_$1}\${GIT_$1}\${ResetColor}" + __add_status "\$GIT_PROMPT_$1\$GIT_$1\$ResetColor" else - __add_status "\${GIT_PROMPT_$1}\${ResetColor}" + __add_status "\$GIT_PROMPT_$1\$ResetColor" fi fi } __add_gitvar_status() { - __add_status "\${GIT_PROMPT_$1}\${GIT_$1}\${ResetColor}" + __add_status "\$GIT_PROMPT_$1\$GIT_$1\$ResetColor" } # __add_status SOMETEXT __add_status() { - eval "STATUS=\"${STATUS}$1\"" + eval "STATUS=\"$STATUS$1\"" } __chk_gitvar_status 'REMOTE' '-n' @@ -268,15 +268,15 @@ function updatePrompt() { __chk_gitvar_status 'UNTRACKED' '-ne 0' __chk_gitvar_status 'STASHED' '-ne 0' __chk_gitvar_status 'CLEAN' '-eq 1' - - __add_status "${ResetColor}$GIT_PROMPT_SUFFIX" + __add_status "$ResetColor$GIT_PROMPT_SUFFIX" - PS1="${LAST_COMMAND_INDICATOR}${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}" - if [[ -n "${VIRTUAL_ENV}" ]]; then - PS1="(${Blue}$(basename \"$VIRTUAL_ENV\")${ResetColor}) ${PS1}" + PS1="$LAST_COMMAND_INDICATOR$PROMPT_START$($prompt_callback)$STATUS$PROMPT_END" + if [[ -n "$VIRTUAL_ENV" ]]; then + PS1="($Blue$(basename \"$VIRTUAL_ENV\")$ResetColor) $PS1" fi - if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then - PS1="(${Blue}$(basename \"$CONDA_DEFAULT_ENV\")${ResetColor}) ${PS1}" + if [[ -n "$CONDA_DEFAULT_ENV" ]]; then + PS1="($Blue$(basename \"$CONDA_DEFAULT_ENV\")$ResetColor) $PS1" fi else From 8a8e068e6682ef2720f01ff25d1fb6c8a2b1a96f Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 28 Aug 2014 21:30:48 +0200 Subject: [PATCH 26/99] Removed declares in git-prompt-colors.sh as they are not compatible with the Bash on MacOS X --- git-prompt-colors.sh | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index aa76a49..7eff7c7 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -1,17 +1,5 @@ # These are the color definitions used by gitprompt.sh -declare -g GIT_PROMPT_PREFIX -declare -g GIT_PROMPT_SUFFIX -declare -g GIT_PROMPT_SEPARATOR -declare -g GIT_PROMPT_BRANCH -declare -g GIT_PROMPT_STAGED -declare -g GIT_PROMPT_CONFLICTS -declare -g GIT_PROMPT_CHANGED -declare -g GIT_PROMPT_REMOTE -declare -g GIT_PROMPT_UNTRACKED -declare -g GIT_PROMPT_STASHED -declare -g GIT_PROMPT_CLEAN - local Time12a="\$(date +%H:%M)" local PathShort="\w" From 957eb80d2a6f5a00d81b209256ec82ec63d2ff77 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 28 Aug 2014 21:44:22 +0200 Subject: [PATCH 27/99] Readded the LAST_COMMAND_INDICATOR-Functionality, which got lost on last merge. Added fix for #67 --- README.md | 10 +++++++++- git-prompt-colors.sh | 6 ++++++ gitprompt.sh | 40 ++++++++++++++++++++++++++++------------ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7f8131b..3fa86df 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,15 @@ function prompt_callback { - You can show an additional indicator at the start of the prompt, which shows the result of the last executed command by setting ``GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1`` before sourcing the gitprompt - script + script. + 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``: + +```sh +GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # displays as ✔-0 +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 diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index 7eff7c7..4d2dd24 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -18,6 +18,12 @@ 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 +# For the command indicator, the placeholder _LAST_COMMAND_STATE_ +# will be replaced with the exit code of the last command +# e.g. +# GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 +# GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 diff --git a/gitprompt.sh b/gitprompt.sh index 50863d0..da136a6 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -62,7 +62,6 @@ function gp_maybe_set_envar_to_path(){ function git_prompt_config() { - #Checking if root to change output _isroot=false [[ $UID -eq 0 ]] && _isroot=true @@ -94,11 +93,13 @@ function git_prompt_config() fi if [ "x${GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR}" == "x1" ]; then - if [ $LAST_COMMAND_STATE = 0 ]; then - LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_OK}"; - else - LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_FAIL}"; - fi + if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then + LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_OK}"; + else + LAST_COMMAND_INDICATOR="${GIT_PROMPT_COMMAND_FAIL}"; + fi + + LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR/_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_STATE}}" fi # Do this only once to define PROMPT_START and PROMPT_END @@ -161,9 +162,11 @@ function git_prompt_config() fi } -function setGitPrompt() { - LAST_COMMAND_STATE=$? +function setLastCommandState() { + GIT_PROMPT_LAST_COMMAND_STATE=$? +} +function setGitPrompt() { local EMPTY_PROMPT local __GIT_STATUS_CMD @@ -181,11 +184,11 @@ function setGitPrompt() { fi if [[ -e "${repo}/.bash-git-rc" ]]; then - source "${repo}/.bash-git-rc" + source "${repo}/.bash-git-rc" fi if [ "x${FETCH_REMOTE_STATUS}" == "x1" ]; then - checkUpstream + checkUpstream fi updatePrompt @@ -294,7 +297,7 @@ function prompt_callback_default { return } -function run { +function gp_install_prompt { if [ "`type -t prompt_callback`" = 'function' ]; then prompt_callback="prompt_callback" else @@ -323,8 +326,21 @@ function run { esac fi + if [ "x${GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR}" == "x1" ]; then + local setLastCommandStateEntry="setLastCommandState" + case ";$PROMPT_COMMAND;" in + *";$setLastCommandStateEntry;"*) + # echo "PROMPT_COMMAND already contains: $setLastCommandStateEntry" + :;; + *) + PROMPT_COMMAND="$setLastCommandStateEntry;$PROMPT_COMMAND" + # echo "PROMPT_COMMAND does not contain: $setLastCommandStateEntry" + ;; + esac + fi + git_prompt_dir source "$__GIT_PROMPT_DIR/git-prompt-help.sh" } -run +gp_install_prompt From 8826ec66ad0f14badf0d8d77d1030740f08c7bd6 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 28 Aug 2014 22:35:36 +0200 Subject: [PATCH 28/99] Fixed typo in color name. Fixes #70 --- prompt-colors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompt-colors.sh b/prompt-colors.sh index cacf7bb..5176d36 100644 --- a/prompt-colors.sh +++ b/prompt-colors.sh @@ -6,7 +6,7 @@ define_color_names() { - ColorNames=( Black Red Green Yellow Blue Magneta Cyan White ) + ColorNames=( Black Red Green Yellow Blue Magenta Cyan White ) FgColors=( 30 31 32 33 34 35 36 37 ) BgColors=( 40 41 42 43 44 45 46 47 ) From f82446c9ac29af66fa4dcc056a67fc469dd19385 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 13:59:33 -0700 Subject: [PATCH 29/99] aks: changed all file envars to end with _FILE; added git_prompt_reset --- gitprompt.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index ed1a5bb..6f95df0 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -67,6 +67,18 @@ function gp_maybe_set_envar_to_path(){ return 1 } +# git_prompt_reset +# +# unsets selected GIT_PROMPT variables, causing the next prompt callback to +# recalculate them from scratch. + +git_prompt_reset() { + local var + for var in GIT_PROMPT_DIR __GIT_PROMPT_COLORS_FILE __PROMPT_COLORS_FILE __GIT_STATUS_CMD ; do + unset $var + done +} + function git_prompt_config() { #Checking if root to change output @@ -78,8 +90,8 @@ function git_prompt_config() # prompt-colors.sh -- sets generic color names suitable for bash `PS1` prompt # git-prompt-colors.sh -- sets the GIT_PROMPT color scheme, using names from prompt-colors.sh - if gp_set_file_var __PROMPT_COLORS_SH prompt-colors.sh ; then - source "$__PROMPT_COLORS_SH" # outsource the color defs + if gp_set_file_var __PROMPT_COLORS_FILE prompt-colors.sh ; then + source "$__PROMPT_COLORS_FILE" # outsource the color defs else echo 1>&2 "Cannot find prompt-colors.sh!" fi @@ -220,8 +232,6 @@ function updatePrompt() { local PROMPT_START local PROMPT_END local EMPTY_PROMPT - local GIT_PROMPT_FETCH_TIMEOUT - local __GIT_STATUS_CMD local Blue="\[\033[0;34m\]" git_prompt_config From 1a144e23db83bfb564b61d406fdc4477b8ef9e72 Mon Sep 17 00:00:00 2001 From: Alan Stebbens Date: Thu, 28 Aug 2014 13:59:46 -0700 Subject: [PATCH 30/99] aks: addd git_prompt_reset --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3fa86df..12abe62 100644 --- a/README.md +++ b/README.md @@ -128,8 +128,16 @@ GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 fo 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 get help on the git prompt with the function ``git_prompt_help``. - Examples are available with ``git_prompt_examples``. +- You can get help on the git prompt with the function ``git_prompt_help``. + Examples are available with ``git_prompt_examples``. + +- 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. + +```sh +git_prompt_reset +``` **Enjoy!** From 81af6557d88629d8966f3665ec78c8274f333892 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Fri, 29 Aug 2014 14:12:55 +0200 Subject: [PATCH 31/99] Added homebrew formula --- bash-git-prompt.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 bash-git-prompt.rb diff --git a/bash-git-prompt.rb b/bash-git-prompt.rb new file mode 100644 index 0000000..ba42857 --- /dev/null +++ b/bash-git-prompt.rb @@ -0,0 +1,23 @@ +require "formula" + +class BashGitPrompt < Formula + homepage "https://github.com/magicmonty/bash-git-prompt" + url "https://github.com/magicmonty/bash-git-prompt/archive/2.0.tar.gz" + head "https://github.com/magicmonty/bash-git-prompt", :using => :git + sha1 "3c0bc71302b97260cf8d14a1f01be732039365b9" + + def install + prefix.install Dir['./*'] + end + + def caveats; <<-EOS.undent + Add the following lines to your .bashrc: + + if [ -f #{prefix}/gitprompt.sh ]; then + . #{prefix}/gitprompt.sh + fi + + For further information see the README.md in #{prefix} + EOS + end +end From d9fef44baa91a8647543ecdc2804bb38ae9f29b5 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 30 Aug 2014 10:35:36 +0200 Subject: [PATCH 32/99] Updated homebrew formula --- bash-git-prompt.rb | 15 +++++++-------- newfile.txt | 0 2 files changed, 7 insertions(+), 8 deletions(-) delete mode 100644 newfile.txt diff --git a/bash-git-prompt.rb b/bash-git-prompt.rb index ba42857..9b05a5c 100644 --- a/bash-git-prompt.rb +++ b/bash-git-prompt.rb @@ -7,17 +7,16 @@ class BashGitPrompt < Formula sha1 "3c0bc71302b97260cf8d14a1f01be732039365b9" def install - prefix.install Dir['./*'] + share.install Dir["./gitprompt.{sh,fish}"] + share.install Dir["./git-prompt-{help,colors}.sh"] + share.install "gitstatus.sh" + share.install "prompt-colors.sh" + doc.install "README.md" end def caveats; <<-EOS.undent - Add the following lines to your .bashrc: - - if [ -f #{prefix}/gitprompt.sh ]; then - . #{prefix}/gitprompt.sh - fi - - For further information see the README.md in #{prefix} + The bash-git-prompt has installed to #{HOMEBREW_PREFIX}/share/gitprompt.sh + See also #{doc}/README.md EOS end end diff --git a/newfile.txt b/newfile.txt deleted file mode 100644 index e69de29..0000000 From c11692ae3f0c9929cf65a0e1568d7ed1b599acc9 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 30 Aug 2014 11:42:46 +0200 Subject: [PATCH 33/99] updated homebrew formula --- bash-git-prompt.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bash-git-prompt.rb b/bash-git-prompt.rb index 9b05a5c..f9f4678 100644 --- a/bash-git-prompt.rb +++ b/bash-git-prompt.rb @@ -7,16 +7,13 @@ class BashGitPrompt < Formula sha1 "3c0bc71302b97260cf8d14a1f01be732039365b9" def install - share.install Dir["./gitprompt.{sh,fish}"] - share.install Dir["./git-prompt-{help,colors}.sh"] - share.install "gitstatus.sh" - share.install "prompt-colors.sh" + share.install Dir["./gitprompt.{sh,fish}"], Dir["./git-prompt-{help,colors}.sh"], "gitstatus.sh", "prompt-colors.sh" doc.install "README.md" end def caveats; <<-EOS.undent - The bash-git-prompt has installed to #{HOMEBREW_PREFIX}/share/gitprompt.sh - See also #{doc}/README.md + You should add the following to your .bashrc or equivalent: + source #{opt_share}/gitprompt.sh EOS end end From 558bc511c23921f7cb836def7d853546433d2016 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 30 Aug 2014 11:47:42 +0200 Subject: [PATCH 34/99] updated README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 12abe62..09e86ff 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,13 @@ staged, changed, etc. `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()``!** + +**Please see the updated ``git-prompt-colors.sh`` in the installation directory!** + ## Examples The prompt may look like the following: From da61d270bbfd43a09d02b3aa2bc9b78cdcd127fb Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 11 Sep 2014 10:37:27 +0200 Subject: [PATCH 35/99] Added BSD license --- LICENSE.txt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..49cb74e --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,23 @@ +Copyright (c) {{{year}}}, {{{fullname}}} +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From 08549e3e76e13a446b4c4ee1aa3178160f5842aa Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 11 Sep 2014 10:38:28 +0200 Subject: [PATCH 36/99] Updated Readme with license, personal info and donation link --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 09e86ff..a8edf06 100644 --- a/README.md +++ b/README.md @@ -196,3 +196,18 @@ rpmbuild -ta bash-git-prompt-xxx.tar.gz Then you may publish or install the rpm from "~/rpmbuild/RPMS/noarch". [blog post]: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ + +## License +This code is under the [BSD 2 Clause (NetBSD) license][license]. + +## Who Are You? +The current maintainer of the original bash-git-prompt is [Martin Gondermann][magicmonty]. + +## Donations +I accept tips through [Gittip][tip]. + +[![Gittip](https://img.shields.io/gittip/magicmonty.svg?style=flat)](https://www.gittip.com/magicmonty/) + +[tip]:https://www.gittip.com/magicmonty/ +[magicmonty]: http://blog.pagansoft.de/pages/about.html +[license]:https://github.com/magicmonty/bash-git-prompt/tree/master/LICENSE.txt From f833ffc0daf48ac306904b2778ab55a0b35ebca6 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 11 Sep 2014 10:51:22 +0200 Subject: [PATCH 37/99] Added Flattr button to Donations on README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a8edf06..35a12ec 100644 --- a/README.md +++ b/README.md @@ -204,10 +204,12 @@ This code is under the [BSD 2 Clause (NetBSD) license][license]. The current maintainer of the original bash-git-prompt is [Martin Gondermann][magicmonty]. ## Donations -I accept tips through [Gittip][tip]. +I accept tips through [Gittip][tip] and [Flattr][flattr]. [![Gittip](https://img.shields.io/gittip/magicmonty.svg?style=flat)](https://www.gittip.com/magicmonty/) +[![Flattr](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=magicmonty&url=https%3A%2F%2Fgithub.com%2Fmagicmonty%2Fbash-git-prompt) [tip]:https://www.gittip.com/magicmonty/ [magicmonty]: http://blog.pagansoft.de/pages/about.html [license]:https://github.com/magicmonty/bash-git-prompt/tree/master/LICENSE.txt +[flattr]: https://flattr.com/submit/auto?user_id=magicmonty&url=https%3A%2F%2Fgithub.com%2Fmagicmonty%2Fbash-git-prompt From 93c0cf4ce488753fb5710000313861683b27cfc7 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Tue, 16 Sep 2014 21:34:55 +0200 Subject: [PATCH 38/99] Added homebrew install documentation to README Fixes #69 --- README.md | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 35a12ec..780fad5 100644 --- a/README.md +++ b/README.md @@ -54,15 +54,37 @@ The symbols are as follows: - 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 :-) -## Install +## Installation -1. Clone this repository to your home directory. +### via [Homebrew][homebrew] on Mac OS X - git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt +- Run `brew update` -2. Source the file `gitprompt.sh` from `~/.bashrc` +- 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 -3. `cd` to a git repository and test it! +- After installing Homebrew should output something like this + +``` +==> Caveats +You should add the following to your .bashrc (or equivalent): + source /usr/local/opt/bash-git-prompt/share/gitprompt.sh +``` + +- Now you can source the file above (`/usr/local/opt/bash-git-prompt/share/gitprompt.sh` in this case) from your `~/.bashrc` + +### via Git clone + +- Clone this repository to your home directory. + +```sh +cd ~ +git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt +``` + +- Source the file `gitprompt.sh` from `~/.bashrc` + +### Configuration ```sh # some other config in .bashrc @@ -71,7 +93,10 @@ The symbols are as follows: # Set config variables first GIT_PROMPT_ONLY_IN_REPO=1 - + + # GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1 # uncomment if you want to show + # the exit code of the last command + # in your prompt # GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status # GIT_PROMPT_START=... # uncomment for custom prompt start sequence @@ -81,7 +106,7 @@ The symbols are as follows: source ~/.bash-git-prompt/gitprompt.sh ``` -- Go in a git repository and test it! +- `cd` to a git repository and test it! - You can define `GIT_PROMPT_START` and `GIT_PROMPT_END` to tweak your prompt. @@ -195,8 +220,6 @@ rpmbuild -ta bash-git-prompt-xxx.tar.gz ```` Then you may publish or install the rpm from "~/rpmbuild/RPMS/noarch". -[blog post]: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ - ## License This code is under the [BSD 2 Clause (NetBSD) license][license]. @@ -209,7 +232,9 @@ I accept tips through [Gittip][tip] and [Flattr][flattr]. [![Gittip](https://img.shields.io/gittip/magicmonty.svg?style=flat)](https://www.gittip.com/magicmonty/) [![Flattr](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=magicmonty&url=https%3A%2F%2Fgithub.com%2Fmagicmonty%2Fbash-git-prompt) +[blog post]: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ [tip]:https://www.gittip.com/magicmonty/ [magicmonty]: http://blog.pagansoft.de/pages/about.html [license]:https://github.com/magicmonty/bash-git-prompt/tree/master/LICENSE.txt [flattr]: https://flattr.com/submit/auto?user_id=magicmonty&url=https%3A%2F%2Fgithub.com%2Fmagicmonty%2Fbash-git-prompt +[homebrew]: http://brew.sh/ From eac8ccf25e2f8eeb7a06783409a9d0ffa4f43137 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Wed, 17 Sep 2014 09:34:25 +0200 Subject: [PATCH 39/99] Updated homebrew instructions in README.md --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 780fad5..ee4387e 100644 --- a/README.md +++ b/README.md @@ -63,15 +63,13 @@ The symbols are as follows: - 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 -- After installing Homebrew should output something like this +- Now you can source the file in your `~/.bashrc` as follows: +```sh +if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then + source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" +fi ``` -==> Caveats -You should add the following to your .bashrc (or equivalent): - source /usr/local/opt/bash-git-prompt/share/gitprompt.sh -``` - -- Now you can source the file above (`/usr/local/opt/bash-git-prompt/share/gitprompt.sh` in this case) from your `~/.bashrc` ### via Git clone From d10f61310043d2b9efe55b5485fc32e5e14405dd Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 18 Sep 2014 21:24:14 +0200 Subject: [PATCH 40/99] Moved VirtualEnv template to git-prompt-colors.sh, fixed replacement --- git-prompt-colors.sh | 11 ++++++++--- gitprompt.sh | 23 ++++++++++++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index 88680c4..c50d2f3 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -23,13 +23,18 @@ define_git_prompt_colors() { # will be replaced with the exit code of the last command # e.g. # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " diff --git a/gitprompt.sh b/gitprompt.sh index 6f95df0..759844d 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -159,9 +159,12 @@ function git_prompt_config() else local ps="$LAST_COMMAND_INDICATOR" if [[ -n "$VIRTUAL_ENV" ]]; then - ps="$ps($Blue$(basename \"$VIRTUAL_ENV\")$ResetColor) " - elif [[ -n "$CONDA_DEFAULT_ENV" ]]; then - ps="$ps($Blue$(basename \"$CONDA_DEFAULT_ENV\")$ResetColor) " + VENV=$(basename "${VIRTUAL_ENV}") + ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" + fi + if [[ -n "$CONDA_DEFAULT_ENV" ]]; then + VENV=$(basename "${CONDA_DEFAULT_ENV}") + ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" fi EMPTY_PROMPT="$ps$PROMPT_START$($prompt_callback)$PROMPT_END" fi @@ -251,6 +254,7 @@ function updatePrompt() { local GIT_STASHED=${GitStatus[6]} local GIT_CLEAN=${GitStatus[7]} + local NEW_PROMPT="$EMPTY_PROMPT" if [[ -n "$GitStatus" ]]; then local STATUS="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}${GIT_BRANCH}${ResetColor}" @@ -292,18 +296,23 @@ function updatePrompt() { __chk_gitvar_status 'CLEAN' '-eq 1' - __add_status "$ResetColor$GIT_PROMPT_SUFFIX" - PS1="$LAST_COMMAND_INDICATOR$PROMPT_START$($prompt_callback)$STATUS$PROMPT_END" + NEW_PROMPT="$LAST_COMMAND_INDICATOR" if [[ -n "$VIRTUAL_ENV" ]]; then - PS1="($Blue$(basename \"$VIRTUAL_ENV\")$ResetColor) $PS1" + VENV=$(basename "${VIRTUAL_ENV}") + NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" fi if [[ -n "$CONDA_DEFAULT_ENV" ]]; then - PS1="($Blue$(basename \"$CONDA_DEFAULT_ENV\")$ResetColor) $PS1" + VENV=$(basename "${CONDA_DEFAULT_ENV}") + NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" fi + NEW_PROMPT="$NEW_PROMPT$PROMPT_START$($prompt_callback)$STATUS$PROMPT_END" else - PS1="$EMPTY_PROMPT" + NEW_PROMPT="$EMPTY_PROMPT" fi + + PS1="$NEW_PROMPT" } function prompt_callback_default { From a647ceb08e4858082c0ba76331f70074a39be50b Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 18 Sep 2014 21:24:54 +0200 Subject: [PATCH 41/99] added helper function git_prompt_color_samples to show a list with all available named colors --- README.md | 1 + git-prompt-help.sh | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 780fad5..4109def 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,7 @@ GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 fo - 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 diff --git a/git-prompt-help.sh b/git-prompt-help.sh index 791bc7f..8b9b390 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -58,3 +58,18 @@ These are examples of the git prompt: EOF } +git_prompt_color_samples() { + + showColor() { + local color=$(eval echo "\${$1}") + echo -e "${color}$1${ResetColor}" | sed 's/\\\]//g' | sed 's/\\\[//g' + } + + while (( x < 8 )) ; do + showColor ${ColorNames[x]} + showColor "Dim${ColorNames[x]}" + showColor "Bold${ColorNames[x]}" + showColor "Bright${ColorNames[x]}" + (( x++ )) + done +} From 3569c97ba024aeffef80e2da4c7373ee768b9753 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Fri, 19 Sep 2014 20:08:48 +0200 Subject: [PATCH 42/99] Ditched the config variable GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR in favor of a more general approach with a placeholder. Fixes #76 --- README.md | 22 +++++++++++++++------- git-prompt-colors.sh | 11 ++++++----- gitprompt.sh | 25 ++++++++++++------------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 72dc3bd..eb54d77 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,11 @@ if you have one. It now contains a function named ``define_git_prompt_colors()`` **Please see the updated ``git-prompt-colors.sh`` in the installation directory!** +--- + +**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: @@ -92,9 +97,6 @@ git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt # Set config variables first GIT_PROMPT_ONLY_IN_REPO=1 - # GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1 # uncomment if you want to show - # the exit code of the last command - # in your prompt # GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status # GIT_PROMPT_START=... # uncomment for custom prompt start sequence @@ -140,10 +142,16 @@ function prompt_callback { - 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 additional indicator at the start of the prompt, which shows - the result of the last executed command by setting - ``GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR=1`` before sourcing the gitprompt - script. +- 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 `git-prompt-colors.sh`: + +```sh + 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``: diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index c50d2f3..9d6a7ed 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -25,16 +25,17 @@ define_git_prompt_colors() { # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 # template for displaying the current virtual environment # use the placeholder _VIRTUALENV_ will be replaced with # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " diff --git a/gitprompt.sh b/gitprompt.sh index 759844d..9f6c290 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -105,17 +105,15 @@ function git_prompt_config() echo 1>&2 "Cannot find git-prompt-colors.sh!" fi - if [ "$GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR" = 1 ]; then - if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then - LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK"; - else - LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_FAIL"; - fi - - # replace _LAST_COMMAND_STATE_ token with the actual state - LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR/_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_STATE}}" + if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then + LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK"; + else + LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_FAIL"; fi + # replace _LAST_COMMAND_STATE_ token with the actual state + LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR/_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_STATE}}" + # Do this only once to define PROMPT_START and PROMPT_END if [[ -z "$PROMPT_START" || -z "$PROMPT_END" ]]; then @@ -157,7 +155,7 @@ function git_prompt_config() if [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then EMPTY_PROMPT="$OLD_GITPROMPT" else - local ps="$LAST_COMMAND_INDICATOR" + local ps="" if [[ -n "$VIRTUAL_ENV" ]]; then VENV=$(basename "${VIRTUAL_ENV}") ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" @@ -166,7 +164,8 @@ function git_prompt_config() VENV=$(basename "${CONDA_DEFAULT_ENV}") ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" fi - EMPTY_PROMPT="$ps$PROMPT_START$($prompt_callback)$PROMPT_END" + ps="$ps$PROMPT_START$($prompt_callback)$PROMPT_END" + EMPTY_PROMPT="${ps/_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" fi # fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes @@ -296,7 +295,7 @@ function updatePrompt() { __chk_gitvar_status 'CLEAN' '-eq 1' - __add_status "$ResetColor$GIT_PROMPT_SUFFIX" - NEW_PROMPT="$LAST_COMMAND_INDICATOR" + NEW_PROMPT="" if [[ -n "$VIRTUAL_ENV" ]]; then VENV=$(basename "${VIRTUAL_ENV}") NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" @@ -312,7 +311,7 @@ function updatePrompt() { NEW_PROMPT="$EMPTY_PROMPT" fi - PS1="$NEW_PROMPT" + PS1="${NEW_PROMPT/_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" } function prompt_callback_default { From 9005bf4260f28b208632de6e6c5eb0de4a141dc6 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Fri, 19 Sep 2014 20:23:14 +0200 Subject: [PATCH 43/99] Fixed a leftover GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR --- gitprompt.sh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 9f6c290..b518055 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -347,18 +347,16 @@ function gp_install_prompt { esac fi - if [ "$GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR" = 1 ]; then - local setLastCommandStateEntry="setLastCommandState" - case ";$PROMPT_COMMAND;" in - *";$setLastCommandStateEntry;"*) - # echo "PROMPT_COMMAND already contains: $setLastCommandStateEntry" - :;; - *) - PROMPT_COMMAND="$setLastCommandStateEntry;$PROMPT_COMMAND" - # echo "PROMPT_COMMAND does not contain: $setLastCommandStateEntry" - ;; - esac - fi + local setLastCommandStateEntry="setLastCommandState" + case ";$PROMPT_COMMAND;" in + *";$setLastCommandStateEntry;"*) + # echo "PROMPT_COMMAND already contains: $setLastCommandStateEntry" + :;; + *) + PROMPT_COMMAND="$setLastCommandStateEntry;$PROMPT_COMMAND" + # echo "PROMPT_COMMAND does not contain: $setLastCommandStateEntry" + ;; + esac git_prompt_dir source "$__GIT_PROMPT_DIR/git-prompt-help.sh" From 882bc8ea46cfd419bcd05123c53c91b9114ca2e6 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 20 Sep 2014 21:56:35 +0200 Subject: [PATCH 44/99] Added first thought on themes --- gitprompt.sh | 69 ++++++++++++++++++++++++-- themes/Default.bgptheme | 1 + themes/NoLastCommandIndicator.bgptheme | 50 +++++++++++++++++++ themes/Original.bgptheme | 50 +++++++++++++++++++ 4 files changed, 165 insertions(+), 5 deletions(-) create mode 120000 themes/Default.bgptheme create mode 100644 themes/NoLastCommandIndicator.bgptheme create mode 100644 themes/Original.bgptheme diff --git a/gitprompt.sh b/gitprompt.sh index b518055..8f43443 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -22,6 +22,68 @@ function git_prompt_dir() fi } +function echoc() { + echo -e "${1}$2${ResetColor}" | sed 's/\\\]//g' | sed 's/\\\[//g' +} + +function get_theme() +{ + if [[ -z ${GIT_PROMPT_THEME} ]]; then + GIT_PROMPT_THEME="Default" + __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + else + if [[ "${GIT_PROMPT_THEME}" = "Custom" ]]; then + GIT_PROMPT_THEME="Custom" + __GIT_PROMPT_THEME_FILE="${HOME}/.git-prompt-colors.sh" + if [[ !(-r $__GIT_PROMPT_THEME_FILE) ]]; then + GIT_PROMPT_THEME="Default" + __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + fi + else + local theme="" + + # use default theme, if theme was not found + for themefile in `ls $__GIT_PROMPT_DIR/themes`; do + if [[ "${themefile}" = "${GIT_PROMPT_THEME}.bgptheme" ]]; then + theme=$GIT_PROMPT_THEME + fi + done + + if [[ "${theme}" = "" ]]; then + GIT_PROMPT_THEME="Default" + fi + + __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/${GIT_PROMPT_THEME}.bgptheme" + fi + fi + +} + +function git_prompt_list_themes() +{ + local oldTheme + local oldThemeFile + + git_prompt_dir + get_theme + + for themefile in `ls $__GIT_PROMPT_DIR/themes`; do + local theme="$(basename $themefile .bgptheme)" + + if [[ "${GIT_PROMPT_THEME}" = "${theme}" ]]; then + echoc ${Red} "*${theme}" + else + echo $theme + fi + done + + if [[ "${GIT_PROMPT_THEME}" = "Custom" ]]; then + echoc ${Magenta} "*Custom" + else + echoc ${Blue} "Custom" + fi +} + # gp_set_file_var ENVAR SOMEFILE # # If ENVAR is set, check that it's value exists as a readable file. Otherwise, @@ -99,11 +161,8 @@ function git_prompt_config() # source the user's ~/.git-prompt-colors.sh file, or the one that should be # sitting in the same directory as this script - if gp_set_file_var __GIT_PROMPT_COLORS_FILE git-prompt-colors.sh ; then - source "$__GIT_PROMPT_COLORS_FILE" - else - echo 1>&2 "Cannot find git-prompt-colors.sh!" - fi + get_theme + source "$__GIT_PROMPT_THEME_FILE" if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK"; diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme new file mode 120000 index 0000000..8e0b4a1 --- /dev/null +++ b/themes/Default.bgptheme @@ -0,0 +1 @@ +Original.bgptheme \ No newline at end of file diff --git a/themes/NoLastCommandIndicator.bgptheme b/themes/NoLastCommandIndicator.bgptheme new file mode 100644 index 0000000..b6309b3 --- /dev/null +++ b/themes/NoLastCommandIndicator.bgptheme @@ -0,0 +1,50 @@ +# These are the color definitions used by gitprompt.sh + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + 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) and the symbols for ahead and behind + 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 + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + # 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 +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi diff --git a/themes/Original.bgptheme b/themes/Original.bgptheme new file mode 100644 index 0000000..9d6a7ed --- /dev/null +++ b/themes/Original.bgptheme @@ -0,0 +1,50 @@ +# These are the color definitions used by gitprompt.sh + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + 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) and the symbols for ahead and behind + 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 + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + # 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 +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi From 71810b95f5a4be352d0e640dd1efc172984686e5 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 21 Sep 2014 13:08:21 +0200 Subject: [PATCH 45/99] moved themes around --- git-prompt-colors.sh | 50 -------------------------- git-prompt-help.sh | 4 +-- themes/Default.bgptheme | 1 - themes/NoLastCommandIndicator.bgptheme | 2 +- themes/Original.bgptheme | 50 -------------------------- 5 files changed, 3 insertions(+), 104 deletions(-) delete mode 100644 git-prompt-colors.sh delete mode 120000 themes/Default.bgptheme delete mode 100644 themes/Original.bgptheme diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh deleted file mode 100644 index 9d6a7ed..0000000 --- a/git-prompt-colors.sh +++ /dev/null @@ -1,50 +0,0 @@ -# These are the color definitions used by gitprompt.sh - -define_git_prompt_colors() { - Time12a="\$(date +%H:%M)" - PathShort="\w" - - # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item - - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory - 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) and the symbols for ahead and behind - 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 - - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ - # will be replaced with the exit code of the last command - # e.g. - # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - - GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 - - # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with - # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL - GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " - GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " - - # 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 -} - -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors -fi diff --git a/git-prompt-help.sh b/git-prompt-help.sh index 8b9b390..d1fe751 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -3,8 +3,8 @@ # being displayed. git_prompt_help() { - source prompt-colors.sh - source git-prompt-colors.sh + source ${__GIT_PROMPT_DIR}/prompt-colors.sh + source themes/Default.bgptheme cat <|] diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme deleted file mode 120000 index 8e0b4a1..0000000 --- a/themes/Default.bgptheme +++ /dev/null @@ -1 +0,0 @@ -Original.bgptheme \ No newline at end of file diff --git a/themes/NoLastCommandIndicator.bgptheme b/themes/NoLastCommandIndicator.bgptheme index b6309b3..751b7ed 100644 --- a/themes/NoLastCommandIndicator.bgptheme +++ b/themes/NoLastCommandIndicator.bgptheme @@ -1,4 +1,4 @@ -# These are the color definitions used by gitprompt.sh +# This is the default theme for gitprompt.sh without the indicator of the last command state define_git_prompt_colors() { Time12a="\$(date +%H:%M)" diff --git a/themes/Original.bgptheme b/themes/Original.bgptheme deleted file mode 100644 index 9d6a7ed..0000000 --- a/themes/Original.bgptheme +++ /dev/null @@ -1,50 +0,0 @@ -# These are the color definitions used by gitprompt.sh - -define_git_prompt_colors() { - Time12a="\$(date +%H:%M)" - PathShort="\w" - - # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item - - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory - 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) and the symbols for ahead and behind - 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 - - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ - # will be replaced with the exit code of the last command - # e.g. - # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - - GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 - - # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with - # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL - GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " - GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " - - # 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 -} - -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors -fi From e31c91802c431dddfc04d9c3d064400562e9cbbd Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 21 Sep 2014 13:08:35 +0200 Subject: [PATCH 46/99] Readded Default theme --- themes/Default.bgptheme | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 themes/Default.bgptheme diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme new file mode 100644 index 0000000..685ab1c --- /dev/null +++ b/themes/Default.bgptheme @@ -0,0 +1,50 @@ +# This is the default theme for gitprompt.sh + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + 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) and the symbols for ahead and behind + 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 + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + # 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 +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi From 09248274652c3db2ec77cc1a6a107401b0112596 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 21 Sep 2014 13:08:59 +0200 Subject: [PATCH 47/99] Added theme optimised for the "Solarized Dark" theme --- themes/SolarizedDark.bgptheme | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 themes/SolarizedDark.bgptheme diff --git a/themes/SolarizedDark.bgptheme b/themes/SolarizedDark.bgptheme new file mode 100644 index 0000000..3c186a6 --- /dev/null +++ b/themes/SolarizedDark.bgptheme @@ -0,0 +1,50 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" color scheme + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Yellow}●" # 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) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${Green}✔" # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " + + # 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 +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi From becb66cf0f46b4f1011ba407459c86a5ae0b743b Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 21 Sep 2014 13:09:25 +0200 Subject: [PATCH 48/99] Added function to derive a custom theme from a given theme --- gitprompt.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gitprompt.sh b/gitprompt.sh index 8f43443..566b79f 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -84,6 +84,30 @@ function git_prompt_list_themes() fi } +function git_prompt_make_custom_theme() { + if [[ -r "${HOME}/.git-prompt-colors.sh" ]]; then + echoc ${Red} "You alread have created a custom theme!" + else + git_prompt_dir + + local base="Default" + if [[ -n $1 && -r "${__GIT_PROMPT_DIR}/themes/${1}.bgptheme" ]]; then + base=$1 + echoc ${Green} "Using theme ${Magenta}\"${base}\"${Green} as base theme!" + else + echoc ${Green} "Using theme ${Magenta}\"Default\"${Green} as base theme!" + fi + + if [[ "${base}" = "Custom" ]]; then + echoc ${Red} "You cannot use the custom theme as base" + else + echoc ${Green} "Creating new cutom theme in \"${HOME}/.git-prompt-colors.sh\"" + echoc ${DimYellow} "Please add ${Magenta}\"GIT_PROMPT_THEME=Custom\"${DimYellow} to your .bashrc to use this theme" + cp "${__GIT_PROMPT_DIR}/themes/${base}.bgptheme" "${HOME}/.git-prompt-colors.sh" + fi + fi +} + # gp_set_file_var ENVAR SOMEFILE # # If ENVAR is set, check that it's value exists as a readable file. Otherwise, From 467ca14bcde72ee15c92e313f9517bf04315e09a Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 21 Sep 2014 13:16:37 +0200 Subject: [PATCH 49/99] Renamed theme SolarizedDark to Solarized, because it matches both variants --- themes/{SolarizedDark.bgptheme => Solarized.bgptheme} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename themes/{SolarizedDark.bgptheme => Solarized.bgptheme} (98%) diff --git a/themes/SolarizedDark.bgptheme b/themes/Solarized.bgptheme similarity index 98% rename from themes/SolarizedDark.bgptheme rename to themes/Solarized.bgptheme index 3c186a6..9a936cf 100644 --- a/themes/SolarizedDark.bgptheme +++ b/themes/Solarized.bgptheme @@ -1,4 +1,4 @@ -# This theme for gitprompt.sh is optimized for the "Solarized Dark" color scheme +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes define_git_prompt_colors() { Time12a="\$(date +%H:%M)" From fa1189b112a31a8d3d1c3fd13e640a16e42b64d9 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Wed, 1 Oct 2014 21:14:04 +0200 Subject: [PATCH 50/99] Added possibility to ignore a repository completely by adding "GIT_PROMPT_IGNORE=1" to .bash-git-rc Fixes #80 --- README.md | 3 +++ gitprompt.sh | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb54d77..756186c 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,9 @@ GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 fo 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. + - 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` diff --git a/gitprompt.sh b/gitprompt.sh index b518055..cc71eef 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -200,11 +200,18 @@ function setGitPrompt() { FETCH_REMOTE_STATUS=0 fi + unset GIT_PROMPT_IGNORE + if [[ -e "$repo/.bash-git-rc" ]]; then source "$repo/.bash-git-rc" fi - if [ "$FETCH_REMOTE_STATUS" = 1 ]; then + if [[ "$GIT_PROMPT_IGNORE" = 1 ]]; then + PS1="$EMPTY_PROMPT" + return + fi + + if [[ "$FETCH_REMOTE_STATUS" = 1 ]]; then checkUpstream fi From 5e4d12bc94d80ea409cac087bbd980b003c49faa Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 4 Oct 2014 21:03:58 +0200 Subject: [PATCH 51/99] Updated home-brew formula --- bash-git-prompt.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bash-git-prompt.rb b/bash-git-prompt.rb index f9f4678..528d80d 100644 --- a/bash-git-prompt.rb +++ b/bash-git-prompt.rb @@ -2,18 +2,19 @@ require "formula" class BashGitPrompt < Formula homepage "https://github.com/magicmonty/bash-git-prompt" - url "https://github.com/magicmonty/bash-git-prompt/archive/2.0.tar.gz" - head "https://github.com/magicmonty/bash-git-prompt", :using => :git - sha1 "3c0bc71302b97260cf8d14a1f01be732039365b9" + url "https://github.com/magicmonty/bash-git-prompt/archive/2.1.tar.gz" + sha1 "9bd29dc2aa4859d2f4c0736cb26cc177de9c1274" + head "https://github.com/magicmonty/bash-git-prompt.git" def install - share.install Dir["./gitprompt.{sh,fish}"], Dir["./git-prompt-{help,colors}.sh"], "gitstatus.sh", "prompt-colors.sh" + share.install "./gitprompt.sh", "./gitprompt.fish", "./git-prompt-help.sh", + "./git-prompt-colors.sh", "gitstatus.sh", "prompt-colors.sh" doc.install "README.md" end def caveats; <<-EOS.undent - You should add the following to your .bashrc or equivalent: - source #{opt_share}/gitprompt.sh + You should add the following to your .bashrc (or equivalent): + source #{opt_share}/gitprompt.sh EOS end end From 7b95c937668334e07dc652a633033e246fce12d6 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 4 Oct 2014 21:21:47 +0200 Subject: [PATCH 52/99] Added themes without display of exit state for Solarized theme, added tweaked themes for Ubuntu terminal fonts (see #77) --- themes/Default.bgptheme | 2 +- ....bgptheme => Default_NoExitState.bgptheme} | 3 +- themes/Default_NoExitState_Ubuntu.bgptheme | 52 +++++++++++++++++++ themes/Default_Ubuntu.bgptheme | 51 ++++++++++++++++++ themes/Solarized.bgptheme | 5 +- themes/Solarized_NoExitState.bgptheme | 51 ++++++++++++++++++ themes/Solarized_NoExitState_Ubuntu.bgptheme | 52 +++++++++++++++++++ themes/Solarized_Ubuntu.bgptheme | 51 ++++++++++++++++++ 8 files changed, 263 insertions(+), 4 deletions(-) rename themes/{NoLastCommandIndicator.bgptheme => Default_NoExitState.bgptheme} (96%) create mode 100644 themes/Default_NoExitState_Ubuntu.bgptheme create mode 100644 themes/Default_Ubuntu.bgptheme create mode 100644 themes/Solarized_NoExitState.bgptheme create mode 100644 themes/Solarized_NoExitState_Ubuntu.bgptheme create mode 100644 themes/Solarized_Ubuntu.bgptheme diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index 685ab1c..fbb56ab 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -26,7 +26,7 @@ define_git_prompt_colors() { # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 # template for displaying the current virtual environment # use the placeholder _VIRTUALENV_ will be replaced with diff --git a/themes/NoLastCommandIndicator.bgptheme b/themes/Default_NoExitState.bgptheme similarity index 96% rename from themes/NoLastCommandIndicator.bgptheme rename to themes/Default_NoExitState.bgptheme index 751b7ed..e238749 100644 --- a/themes/NoLastCommandIndicator.bgptheme +++ b/themes/Default_NoExitState.bgptheme @@ -1,4 +1,5 @@ -# This is the default theme for gitprompt.sh without the indicator of the last command state +# This is the default theme for gitprompt.sh +# without the indicator of the last command state define_git_prompt_colors() { Time12a="\$(date +%H:%M)" diff --git a/themes/Default_NoExitState_Ubuntu.bgptheme b/themes/Default_NoExitState_Ubuntu.bgptheme new file mode 100644 index 0000000..1f7a1e7 --- /dev/null +++ b/themes/Default_NoExitState_Ubuntu.bgptheme @@ -0,0 +1,52 @@ +# This is the default theme for gitprompt.sh +# without the indicator of the last command state +# tweaked for Ubuntu terminal fonts + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + 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) and the symbols for ahead and behind + 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 + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + # 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 +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi diff --git a/themes/Default_Ubuntu.bgptheme b/themes/Default_Ubuntu.bgptheme new file mode 100644 index 0000000..a1b54b0 --- /dev/null +++ b/themes/Default_Ubuntu.bgptheme @@ -0,0 +1,51 @@ +# This is the default theme for gitprompt.sh +# tweaked for Ubuntu terminal fonts + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + 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) and the symbols for ahead and behind + 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 + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + # 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 +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi diff --git a/themes/Solarized.bgptheme b/themes/Solarized.bgptheme index 9a936cf..7825fd2 100644 --- a/themes/Solarized.bgptheme +++ b/themes/Solarized.bgptheme @@ -1,4 +1,5 @@ -# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# tweaked for Ubuntu terminal fonts define_git_prompt_colors() { Time12a="\$(date +%H:%M)" @@ -26,7 +27,7 @@ define_git_prompt_colors() { # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 # template for displaying the current virtual environment # use the placeholder _VIRTUALENV_ will be replaced with diff --git a/themes/Solarized_NoExitState.bgptheme b/themes/Solarized_NoExitState.bgptheme new file mode 100644 index 0000000..a2108d7 --- /dev/null +++ b/themes/Solarized_NoExitState.bgptheme @@ -0,0 +1,51 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# without the indicator of the last command state + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Yellow}●" # 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) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${Green}✔" # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " + + # 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 +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi diff --git a/themes/Solarized_NoExitState_Ubuntu.bgptheme b/themes/Solarized_NoExitState_Ubuntu.bgptheme new file mode 100644 index 0000000..d8cab5e --- /dev/null +++ b/themes/Solarized_NoExitState_Ubuntu.bgptheme @@ -0,0 +1,52 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# without the indicator of the last command state +# tweaked for Ubuntu terminal fonts + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Yellow}● " # 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) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}… " # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${Green}✔ " # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " + + # 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 +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi diff --git a/themes/Solarized_Ubuntu.bgptheme b/themes/Solarized_Ubuntu.bgptheme new file mode 100644 index 0000000..3b7b146 --- /dev/null +++ b/themes/Solarized_Ubuntu.bgptheme @@ -0,0 +1,51 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# tweaked for Ubuntu terminal fonts + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Yellow}● " # 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) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}… " # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${Green}✔ " # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " + + # 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 +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi From 296a04b76f50ce627fdd684b15e4f4e39e65fead Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 4 Oct 2014 21:33:49 +0200 Subject: [PATCH 53/99] Tweaks for backwards compatibility --- gitprompt.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 5ffe722..a172acb 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -28,16 +28,25 @@ function echoc() { function get_theme() { + local CUSTOM_THEME_FILE="${HOME}/.git-prompt-colors.sh" + local DEFAULT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + if [[ -z ${GIT_PROMPT_THEME} ]]; then - GIT_PROMPT_THEME="Default" - __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + if [[ -r $CUSTOM_THEME_FILE ]]; then + GIT_PROMPT_THEME="Custom" + __GIT_PROMPT_THEME_FILE=$CUSTOM_THEME_FILE + else + GIT_PROMPT_THEME="Default" + __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE + fi else if [[ "${GIT_PROMPT_THEME}" = "Custom" ]]; then GIT_PROMPT_THEME="Custom" - __GIT_PROMPT_THEME_FILE="${HOME}/.git-prompt-colors.sh" + __GIT_PROMPT_THEME_FILE=$CUSTOM_THEME_FILE + if [[ !(-r $__GIT_PROMPT_THEME_FILE) ]]; then GIT_PROMPT_THEME="Default" - __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE fi else local theme="" @@ -56,7 +65,6 @@ function get_theme() __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/${GIT_PROMPT_THEME}.bgptheme" fi fi - } function git_prompt_list_themes() From 43a0d72df3af12a2686440f6f9fc512d85c46c03 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 4 Oct 2014 22:00:13 +0200 Subject: [PATCH 54/99] Updated README --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 756186c..2fe64fe 100644 --- a/README.md +++ b/README.md @@ -103,11 +103,34 @@ git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt # GIT_PROMPT_END=... # uncomment for custom prompt end sequence # as last entry source the gitprompt script + # GIT_PROMPT_THEME=Custom # use custom .git-prompt-colors.sh + # GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme source ~/.bash-git-prompt/gitprompt.sh ``` - `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 `/themes` without the extension `.bgptheme` like this: + +```sh +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 []`. 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. + +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.** + +#### 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 From 62efaa9e4683c2dd7a429a538ef837d76479f7bd Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Tue, 7 Oct 2014 19:48:49 +0200 Subject: [PATCH 55/99] Theme always fell back to default theme in bash 3.2.53 Fixes #84 --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index a172acb..c577fe5 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -44,7 +44,7 @@ function get_theme() GIT_PROMPT_THEME="Custom" __GIT_PROMPT_THEME_FILE=$CUSTOM_THEME_FILE - if [[ !(-r $__GIT_PROMPT_THEME_FILE) ]]; then + if [[ ! (-r $__GIT_PROMPT_THEME_FILE) ]]; then GIT_PROMPT_THEME="Default" __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE fi From c04317996d6dce5fe0c968db3aac8f93796e2ac9 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Tue, 7 Oct 2014 20:24:50 +0200 Subject: [PATCH 56/99] gitstatus.sh was not theme aware fixes #83 --- gitprompt.sh | 12 ++++++++++-- gitstatus.sh | 42 +++--------------------------------------- 2 files changed, 13 insertions(+), 41 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index c577fe5..d824692 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -326,6 +326,14 @@ function checkUpstream() { fi } +function replaceSymbols() +{ + local VALUE=${1/_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}} + local VALUE1=${VALUE/_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}} + + echo ${VALUE1/_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} +} + function updatePrompt() { local LAST_COMMAND_INDICATOR local PROMPT_LEADING_SPACE @@ -339,8 +347,8 @@ function updatePrompt() { local -a GitStatus GitStatus=($("$__GIT_STATUS_CMD" 2>/dev/null)) - local GIT_BRANCH=${GitStatus[0]} - local GIT_REMOTE=${GitStatus[1]} + local GIT_BRANCH=$(replaceSymbols ${GitStatus[0]}) + local GIT_REMOTE="$(replaceSymbols ${GitStatus[1]})" if [[ "." == "$GIT_REMOTE" ]]; then unset GIT_REMOTE fi diff --git a/gitstatus.sh b/gitstatus.sh index ba210b5..565c32b 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -19,42 +19,6 @@ if [ -z "${__GIT_PROMPT_DIR}" ]; then __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" fi -if [[ -z "$__GIT_PROMPT_COLORS_FILE" ]]; then - for dir in "$HOME" "$__GIT_PROMPT_DIR" ; do - for pfx in '.' '' ; do - file="$dir/${pfx}git-prompt-colors.sh" - if [[ -f "$file" ]]; then - __GIT_PROMPT_COLORS_FILE="$file" - break 2 - fi - done - done -fi - -# if the envar is defined, source the file for custom colors -if [[ -n "$__GIT_PROMPT_COLORS_FILE" && -f "$__GIT_PROMPT_COLORS_FILE" ]]; then - source "$__GIT_PROMPT_COLORS_FILE" -fi - -# change those symbols to whatever you prefer -if [[ -n "${GIT_PROMPT_SYMBOLS_AHEAD}" ]]; then - symbols_ahead="${GIT_PROMPT_SYMBOLS_AHEAD}" -else - symbols_ahead='↑·' -fi - -if [[ -n "${GIT_PROMPT_SYMBOLS_BEHIND}" ]]; then - symbols_behind="${GIT_PROMPT_SYMBOLS_BEHIND}" -else - symbols_behind='↓·' -fi - -if [[ -n "${GIT_PROMPT_SYMBOLS_PREHASH}" ]]; then - symbols_prehash=':' -else - symbols_prehash="${GIT_PROMPT_SYMBOLS_PREHASH}" -fi - gitsym=`git symbolic-ref HEAD` # if "fatal: Not a git repo .., then exit @@ -93,7 +57,7 @@ if [[ -z "$branch" ]]; then if [[ -n "$tag" ]]; then branch="$tag" else - branch="${symbols_prehash}`git rev-parse --short HEAD`" + branch="_PREHASH_`git rev-parse --short HEAD`" fi else remote_name=`git config branch.${branch}.remote` @@ -126,10 +90,10 @@ else num_ahead=`count_lines "$revgit" "^>"` num_behind=$(( num_revs - num_ahead )) if (( num_behind > 0 )) ; then - remote="${remote}${symbols_behind}${num_behind}" + remote="${remote}_BEHIND_${num_behind}" fi if (( num_ahead > 0 )) ; then - remote="${remote}${symbols_ahead}${num_ahead}" + remote="${remote}_AHEAD_${num_ahead}" fi fi From c370fb33923e8ed38b87a5ee147338ba95029cd0 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Wed, 8 Oct 2014 22:37:41 +0200 Subject: [PATCH 57/99] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2fe64fe..bb04c70 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ staged, changed, etc. **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()``!** -**Please see the updated ``git-prompt-colors.sh`` in the installation directory!** +**Please see the updated ``Default.bgptheme`` in the ``themes`` subdirectory of the installation directory!** --- From 6118c4ae0174a23fadb955bb1a97bf63b83a9cfd Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Wed, 8 Oct 2014 22:47:51 +0200 Subject: [PATCH 58/99] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bb04c70..996297f 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ in your home directory, then the Custom theme is used.** - 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 - `git-prompt-colors.sh`. Both of these files may be overridden by copying + `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. @@ -168,7 +168,7 @@ function prompt_callback { - 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 `git-prompt-colors.sh`: + It is now by default activated in the default theme: ```sh GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" @@ -180,7 +180,7 @@ function prompt_callback { in your ``.git-prompt-colors.sh``: ```sh -GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # displays as ✔-0 +GIT_PROMPT_COMMAND_OK="${Green}✔ " # displays as ✔ GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 for exit code 1 ``` From 7cd27e27dfbb9d5663b27157c00fd69b6c9cfa97 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Wed, 8 Oct 2014 22:53:22 +0200 Subject: [PATCH 59/99] Removed obsolete Time variables in gitprompt.sh FIxes #86 --- gitprompt.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index d824692..1c18ce3 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -209,12 +209,6 @@ function git_prompt_config() if [[ -z "$PROMPT_START" || -z "$PROMPT_END" ]]; then - # Various variables you might want for your PS1 prompt instead - local Time12a="\$(date +%H:%M)" - # local Time12a="(\$(date +%H:%M:%S))" - # local Time12a="(\@))" - local PathShort="\w" - if [[ -z "$GIT_PROMPT_START" ]] ; then if $_isroot; then PROMPT_START="$GIT_PROMPT_START_ROOT" From b745d72722490e47a2aa23b644c26cfae456d4b2 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 9 Oct 2014 21:51:31 +0200 Subject: [PATCH 60/99] Optimized themes --- gitprompt.sh | 32 +++++-- gitstatus.sh | 2 +- themes/Custom.bgptemplate | 53 +++++++++++ themes/Default.bgptheme | 94 ++++++++++++++------ themes/Default_NoExitState.bgptheme | 46 +--------- themes/Default_NoExitState_Ubuntu.bgptheme | 42 +-------- themes/Default_Ubuntu.bgptheme | 45 +--------- themes/Solarized.bgptheme | 50 ++--------- themes/Solarized_NoExitState.bgptheme | 49 ++-------- themes/Solarized_NoExitState_Ubuntu.bgptheme | 51 ++--------- themes/Solarized_Ubuntu.bgptheme | 52 ++--------- 11 files changed, 186 insertions(+), 330 deletions(-) create mode 100644 themes/Custom.bgptemplate diff --git a/gitprompt.sh b/gitprompt.sh index 1c18ce3..1e3e691 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -9,7 +9,7 @@ function async_run() function git_prompt_dir() { - # assume the gitstatus.py is in the same directory as this script + # assume the gitstatus.sh is in the same directory as this script # code thanks to http://stackoverflow.com/questions/59895 if [ -z "$__GIT_PROMPT_DIR" ]; then local SOURCE="${BASH_SOURCE[0]}" @@ -67,6 +67,14 @@ function get_theme() fi } +function git_prompt_load_theme() +{ + get_theme + local DEFAULT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + source "${DEFAULT_THEME_FILE}" + source "${__GIT_PROMPT_THEME_FILE}" +} + function git_prompt_list_themes() { local oldTheme @@ -111,7 +119,11 @@ function git_prompt_make_custom_theme() { else echoc ${Green} "Creating new cutom theme in \"${HOME}/.git-prompt-colors.sh\"" echoc ${DimYellow} "Please add ${Magenta}\"GIT_PROMPT_THEME=Custom\"${DimYellow} to your .bashrc to use this theme" - cp "${__GIT_PROMPT_DIR}/themes/${base}.bgptheme" "${HOME}/.git-prompt-colors.sh" + if [[ "${base}" == "Default" ]]; then + cp "${__GIT_PROMPT_DIR}/themes/Custom.bgptemplate" "${HOME}/.git-prompt-colors.sh" + else + cp "${__GIT_PROMPT_DIR}/themes/${base}.bgptheme" "${HOME}/.git-prompt-colors.sh" + fi fi fi } @@ -168,7 +180,7 @@ function gp_maybe_set_envar_to_path(){ git_prompt_reset() { local var - for var in GIT_PROMPT_DIR __GIT_PROMPT_COLORS_FILE __PROMPT_COLORS_FILE __GIT_STATUS_CMD ; do + for var in GIT_PROMPT_DIR __GIT_PROMPT_COLORS_FILE __PROMPT_COLORS_FILE __GIT_STATUS_CMD GIT_PROMPT_THEME_NAME; do unset $var done } @@ -193,8 +205,7 @@ function git_prompt_config() # source the user's ~/.git-prompt-colors.sh file, or the one that should be # sitting in the same directory as this script - get_theme - source "$__GIT_PROMPT_THEME_FILE" + git_prompt_load_theme if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK"; @@ -257,8 +268,8 @@ function git_prompt_config() GIT_PROMPT_FETCH_TIMEOUT=${1-5} if [[ -z "$__GIT_STATUS_CMD" ]] ; then # if GIT_STATUS_CMD not defined.. git_prompt_dir - if ! gp_maybe_set_envar_to_path __GIT_STATUS_CMD "$__GIT_PROMPT_DIR/gitstatus.sh" "$__GIT_PROMPT_DIR/gitstatus.py" ; then - echo 1>&2 "Cannot find gitstatus.sh or gitstatus.py!" + if ! gp_maybe_set_envar_to_path __GIT_STATUS_CMD "$__GIT_PROMPT_DIR/gitstatus.sh" ; then + echo 1>&2 "Cannot find gitstatus.sh!" fi # __GIT_STATUS_CMD defined fi @@ -322,10 +333,15 @@ function checkUpstream() { function replaceSymbols() { + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING=L + fi + local VALUE=${1/_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}} local VALUE1=${VALUE/_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}} + local VALUE2=${VALUE1/_NO_REMOTE_TRACKING_/${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING}} - echo ${VALUE1/_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} + echo ${VALUE2/_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} } function updatePrompt() { diff --git a/gitstatus.sh b/gitstatus.sh index 565c32b..601e4cf 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -102,7 +102,7 @@ if [[ -z "$remote" ]] ; then fi if [[ "$has_remote_tracking" == "0" ]] ; then - remote='L' + remote='_NO_REMOTE_TRACKING_' fi for w in "$branch" "$remote" $num_staged $num_conflicts $num_changed $num_untracked $num_stashed $clean ; do diff --git a/themes/Custom.bgptemplate b/themes/Custom.bgptemplate new file mode 100644 index 0000000..8305d70 --- /dev/null +++ b/themes/Custom.bgptemplate @@ -0,0 +1,53 @@ +# This is the custom theme template for gitprompt.sh + +# These are the defaults from the "Default" theme +# You just need to override what you want to have changed +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Custom" + + # Time12a="\$(date +%H:%M)" + # PathShort="\w"; + + ## These are the color definitions used by gitprompt.sh + # GIT_PROMPT_PREFIX="[" # start of the git info string + # GIT_PROMPT_SUFFIX="]" # the end of the git info string + # GIT_PROMPT_SEPARATOR="|" # separates each item + + # GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + # 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) and the symbols for ahead and behind + # 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 + + ## For the command indicator, the placeholder _LAST_COMMAND_STATE_ + ## will be replaced with the exit code of the last command + ## e.g. + ## GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + ## GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + # GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 + + ## template for displaying the current virtual environment + ## use the placeholder _VIRTUALENV_ will be replaced with + ## the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + # GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + ## _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + # GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + # GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + # GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + # GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + ## 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 + # GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L" # This symbol is written after the branch, if the branch is not tracked +} + +reload_git_prompt_colors "Custom" \ No newline at end of file diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index fbb56ab..d415eaf 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -1,23 +1,55 @@ # This is the default theme for gitprompt.sh -define_git_prompt_colors() { +unset_git_prompt_colors() { + unset Time12a + unset PathShort + unset GIT_PROMPT_PREFIX + unset GIT_PROMPT_SUFFIX + unset GIT_PROMPT_SEPARATOR + unset GIT_PROMPT_BRANCH + unset GIT_PROMPT_STAGED + unset GIT_PROMPT_CONFLICTS + unset GIT_PROMPT_CHANGED + unset GIT_PROMPT_REMOTE + unset GIT_PROMPT_UNTRACKED + unset GIT_PROMPT_STASHED + unset GIT_PROMPT_CLEAN + unset GIT_PROMPT_COMMAND_OK + unset GIT_PROMPT_COMMAND_FAIL + unset GIT_PROMPT_VIRTUALENV + unset GIT_PROMPT_START_USER + unset GIT_PROMPT_START_ROOT + unset GIT_PROMPT_END_USER + unset GIT_PROMPT_END_ROOT + unset GIT_PROMPT_SYMBOLS_AHEAD + unset GIT_PROMPT_SYMBOLS_BEHIND + unset GIT_PROMPT_SYMBOLS_PREHASH + unset GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING +} + +define_helpers() +{ Time12a="\$(date +%H:%M)" - PathShort="\w" + PathShort="\w"; +} + +define_undefined_git_prompt_colors() { + if [[ -z ${GIT_PROMPT_THEME_NAME} ]]; then GIT_PROMPT_THEME_NAME="Default"; fi # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item + if [[ -z ${GIT_PROMPT_PREFIX} ]]; then GIT_PROMPT_PREFIX="["; fi # start of the git info string + if [[ -z ${GIT_PROMPT_SUFFIX} ]]; then GIT_PROMPT_SUFFIX="]"; fi # the end of the git info string + if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR="|"; fi # separates each item - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory - 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 + if [[ -z ${GIT_PROMPT_BRANCH} ]]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory + if [[ -z ${GIT_PROMPT_STAGED} ]]; then GIT_PROMPT_STAGED="${Red}●"; fi # the number of staged files/directories + if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS="${Red}✖ "; fi # the number of files in conflict + if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED="${Blue}✚ "; fi # the number of changed files - GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind - 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 + if [[ -z ${GIT_PROMPT_REMOTE} ]]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind + if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED="${Cyan}…"; fi # the number of untracked files/dirs + if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED="${BoldBlue}⚑ "; fi # the number of stashed files/dir + if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN="${BoldGreen}✔"; fi # a colored flag indicating a "clean" repo # For the command indicator, the placeholder _LAST_COMMAND_STATE_ # will be replaced with the exit code of the last command @@ -25,26 +57,38 @@ define_git_prompt_colors() { # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 + if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 + if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_"; fi # indicator if the last command returned with an exit code of other than 0 # template for displaying the current virtual environment # use the placeholder _VIRTUALENV_ will be replaced with # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + if [[ -z ${GIT_PROMPT_VIRTUALENV} ]]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL - GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " - GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"; fi + if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}"; fi + if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ "; fi + if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # "; fi # 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 + if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked +} + +# call only from theme file +reload_git_prompt_colors() { + if [[ "${GIT_PROMPT_THEME_NAME}" != $1 ]]; then + unset_git_prompt_colors + define_helpers + override_git_prompt_colors + define_undefined_git_prompt_colors + fi } -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors +if [[ "${GIT_PROMPT_THEME}" == "Default" && "${GIT_PROMPT_THEME_NAME}" != "Default" ]]; then + define_helpers + define_undefined_git_prompt_colors fi diff --git a/themes/Default_NoExitState.bgptheme b/themes/Default_NoExitState.bgptheme index e238749..239aae1 100644 --- a/themes/Default_NoExitState.bgptheme +++ b/themes/Default_NoExitState.bgptheme @@ -1,51 +1,11 @@ # This is the default theme for gitprompt.sh # without the indicator of the last command state -define_git_prompt_colors() { - Time12a="\$(date +%H:%M)" - PathShort="\w" - - # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item - - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory - 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) and the symbols for ahead and behind - 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 - - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ - # will be replaced with the exit code of the last command - # e.g. - # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - - GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Default NoExitState" GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 - - # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with - # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " - GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " - - # 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 } -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors -fi +reload_git_prompt_colors "Default NoExitState" diff --git a/themes/Default_NoExitState_Ubuntu.bgptheme b/themes/Default_NoExitState_Ubuntu.bgptheme index 1f7a1e7..2af22f3 100644 --- a/themes/Default_NoExitState_Ubuntu.bgptheme +++ b/themes/Default_NoExitState_Ubuntu.bgptheme @@ -2,51 +2,15 @@ # without the indicator of the last command state # tweaked for Ubuntu terminal fonts -define_git_prompt_colors() { - Time12a="\$(date +%H:%M)" - PathShort="\w" - - # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item - - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Default NoExitState Ubuntu" 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) and the symbols for ahead and behind 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 - - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ - # will be replaced with the exit code of the last command - # e.g. - # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 - - # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with - # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " - GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " - - # 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 } -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors -fi +reload_git_prompt_colors "Default NoExitState Ubuntu" \ No newline at end of file diff --git a/themes/Default_Ubuntu.bgptheme b/themes/Default_Ubuntu.bgptheme index a1b54b0..7ddf91f 100644 --- a/themes/Default_Ubuntu.bgptheme +++ b/themes/Default_Ubuntu.bgptheme @@ -1,51 +1,12 @@ # This is the default theme for gitprompt.sh # tweaked for Ubuntu terminal fonts -define_git_prompt_colors() { - Time12a="\$(date +%H:%M)" - PathShort="\w" - - # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item - - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Default Ubuntu" 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) and the symbols for ahead and behind 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 - - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ - # will be replaced with the exit code of the last command - # e.g. - # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 - - # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with - # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL - GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " - GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " - - # 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 } -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors -fi +reload_git_prompt_colors "Default Ubuntu" \ No newline at end of file diff --git a/themes/Solarized.bgptheme b/themes/Solarized.bgptheme index 7825fd2..caf1ea8 100644 --- a/themes/Solarized.bgptheme +++ b/themes/Solarized.bgptheme @@ -1,51 +1,13 @@ # This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes # tweaked for Ubuntu terminal fonts -define_git_prompt_colors() { - Time12a="\$(date +%H:%M)" - PathShort="\w" - - # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item - - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory - GIT_PROMPT_STAGED="${Yellow}●" # 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) and the symbols for ahead and behind - GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs - GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir - GIT_PROMPT_CLEAN="${Green}✔" # a colored flag indicating a "clean" repo - - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ - # will be replaced with the exit code of the last command - # e.g. - # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - - GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 - - # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with - # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL - GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized" + GIT_PROMPT_STAGED="${Yellow}●" + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔" GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " - - # 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 } -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors -fi +reload_git_prompt_colors "Solarized" \ No newline at end of file diff --git a/themes/Solarized_NoExitState.bgptheme b/themes/Solarized_NoExitState.bgptheme index a2108d7..77f8e50 100644 --- a/themes/Solarized_NoExitState.bgptheme +++ b/themes/Solarized_NoExitState.bgptheme @@ -1,51 +1,16 @@ # This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes # without the indicator of the last command state -define_git_prompt_colors() { - Time12a="\$(date +%H:%M)" - PathShort="\w" - - # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item - - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory - GIT_PROMPT_STAGED="${Yellow}●" # 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) and the symbols for ahead and behind - GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs - GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir - GIT_PROMPT_CLEAN="${Green}✔" # a colored flag indicating a "clean" repo - - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ - # will be replaced with the exit code of the last command - # e.g. - # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - - GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 - - # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with - # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized NoExitState" + GIT_PROMPT_STAGED="${Yellow}●" + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔" + GIT_PROMPT_COMMAND_FAIL="${Red}✘" GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " - - # 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 } -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors -fi +reload_git_prompt_colors "Solarized NoExitState" \ No newline at end of file diff --git a/themes/Solarized_NoExitState_Ubuntu.bgptheme b/themes/Solarized_NoExitState_Ubuntu.bgptheme index d8cab5e..ae47548 100644 --- a/themes/Solarized_NoExitState_Ubuntu.bgptheme +++ b/themes/Solarized_NoExitState_Ubuntu.bgptheme @@ -2,51 +2,18 @@ # without the indicator of the last command state # tweaked for Ubuntu terminal fonts -define_git_prompt_colors() { - Time12a="\$(date +%H:%M)" - PathShort="\w" - - # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item - - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory - GIT_PROMPT_STAGED="${Yellow}● " # 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) and the symbols for ahead and behind - GIT_PROMPT_UNTRACKED="${Cyan}… " # the number of untracked files/dirs - GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir - GIT_PROMPT_CLEAN="${Green}✔ " # a colored flag indicating a "clean" repo - - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ - # will be replaced with the exit code of the last command - # e.g. - # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - - GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 - - # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with - # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized NoExitState Ubuntu" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_UNTRACKED="${Cyan}… " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " - - # 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 } -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors -fi +reload_git_prompt_colors "Solarized NoExitState Ubuntu" \ No newline at end of file diff --git a/themes/Solarized_Ubuntu.bgptheme b/themes/Solarized_Ubuntu.bgptheme index 3b7b146..a60a0ef 100644 --- a/themes/Solarized_Ubuntu.bgptheme +++ b/themes/Solarized_Ubuntu.bgptheme @@ -1,51 +1,15 @@ # This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes # tweaked for Ubuntu terminal fonts -define_git_prompt_colors() { - Time12a="\$(date +%H:%M)" - PathShort="\w" - - # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item - - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory - GIT_PROMPT_STAGED="${Yellow}● " # 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) and the symbols for ahead and behind - GIT_PROMPT_UNTRACKED="${Cyan}… " # the number of untracked files/dirs - GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir - GIT_PROMPT_CLEAN="${Green}✔ " # a colored flag indicating a "clean" repo - - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ - # will be replaced with the exit code of the last command - # e.g. - # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - - GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 - - # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with - # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL - GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized Ubuntu" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_UNTRACKED="${Cyan}… " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " - - # 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 } -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors -fi +reload_git_prompt_colors "Solarized Ubuntu" \ No newline at end of file From a4a79027d9ae8d80dc3fe6ab26b2d4b24ac1293f Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 11 Oct 2014 14:45:23 +0200 Subject: [PATCH 61/99] Updated README --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 996297f..e7f8dcf 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,27 @@ staged, changed, etc. # 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()``!** +**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 updated ``Default.bgptheme`` in the ``themes`` subdirectory of the installation directory!** +**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 ` 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. --- @@ -129,6 +146,29 @@ You can display a list of available themes with `git_prompt_list_themes` (the cu **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.** +##### 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 ` 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. + +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. @@ -259,6 +299,12 @@ This code is under the [BSD 2 Clause (NetBSD) license][license]. ## Who Are You? The current maintainer of the original bash-git-prompt is [Martin Gondermann][magicmonty]. +## Contributing +If you want to contribute you can look for issues with the label [up-for-grabs][upforgrabs]. +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. + ## Donations I accept tips through [Gittip][tip] and [Flattr][flattr]. @@ -271,3 +317,4 @@ I accept tips through [Gittip][tip] and [Flattr][flattr]. [license]:https://github.com/magicmonty/bash-git-prompt/tree/master/LICENSE.txt [flattr]: https://flattr.com/submit/auto?user_id=magicmonty&url=https%3A%2F%2Fgithub.com%2Fmagicmonty%2Fbash-git-prompt [homebrew]: http://brew.sh/ +[upforgrabs]: https://github.com/magicmonty/bash-git-prompt/labels/up-for-grabs \ No newline at end of file From 1d9cc2fcbe17f7fb5b0b1ec8e289a72316e309c3 Mon Sep 17 00:00:00 2001 From: Bernhard Graf Date: Sat, 11 Oct 2014 19:03:56 +0200 Subject: [PATCH 62/99] Fixed RPM build. - use only $VER (no more $VER1) to avoid confusion - added themes directory --- README.md | 7 ++++--- bash-git-prompt.spec | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e7f8dcf..3735b5b 100644 --- a/README.md +++ b/README.md @@ -260,10 +260,10 @@ from scratch by following this procedure: * Run the following command to create a tarball: ````sh - VER1=$(git describe) + VER=$(git describe) # replace dash with underscore to work around # rpmbuild does not allow dash in version string - VER=${VER1//\-/_} + VER=${VER//\-/_} git archive \ --format tar \ --prefix=bash-git-prompt-${VER}/ \ @@ -272,6 +272,7 @@ from scratch by following this procedure: *.py \ *.fish \ README.md \ + themes \ > bash-git-prompt-${VER}.tar mkdir -p /tmp/bash-git-prompt-${VER} sed "s/Version:.*/Version: ${VER}/" \ @@ -317,4 +318,4 @@ I accept tips through [Gittip][tip] and [Flattr][flattr]. [license]:https://github.com/magicmonty/bash-git-prompt/tree/master/LICENSE.txt [flattr]: https://flattr.com/submit/auto?user_id=magicmonty&url=https%3A%2F%2Fgithub.com%2Fmagicmonty%2Fbash-git-prompt [homebrew]: http://brew.sh/ -[upforgrabs]: https://github.com/magicmonty/bash-git-prompt/labels/up-for-grabs \ No newline at end of file +[upforgrabs]: https://github.com/magicmonty/bash-git-prompt/labels/up-for-grabs diff --git a/bash-git-prompt.spec b/bash-git-prompt.spec index a381b78..f2309c6 100644 --- a/bash-git-prompt.spec +++ b/bash-git-prompt.spec @@ -34,6 +34,8 @@ install -pm 755 *.sh %{buildroot}%{_datadir}/%{name} install -pm 755 *.py %{buildroot}%{_datadir}/%{name} install -pm 755 *.fish %{buildroot}%{_datadir}/%{name} install -pm 644 README.md %{buildroot}%{_datadir}/%{name} +install -d 755 %{buildroot}%{_datadir}/%{name}/themes +install -pm 644 themes/*.bgptheme %{buildroot}%{_datadir}/%{name}/themes # never include compiled Python program rm -fr %{buildroot}%{_datadir}/%{name}/*.pyo From ecb1fd955ed4141f62aba37e5accc6ee348991c5 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 11 Oct 2014 21:08:09 +0200 Subject: [PATCH 63/99] Added custom template and theme variable to RPM spec --- bash-git-prompt.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bash-git-prompt.spec b/bash-git-prompt.spec index f2309c6..ab5f0a1 100644 --- a/bash-git-prompt.spec +++ b/bash-git-prompt.spec @@ -36,6 +36,7 @@ install -pm 755 *.fish %{buildroot}%{_datadir}/%{name} install -pm 644 README.md %{buildroot}%{_datadir}/%{name} install -d 755 %{buildroot}%{_datadir}/%{name}/themes install -pm 644 themes/*.bgptheme %{buildroot}%{_datadir}/%{name}/themes +install -pm 644 themes/*.bgptemplate %{buildroot}%{_datadir}/%{name}/themes # never include compiled Python program rm -fr %{buildroot}%{_datadir}/%{name}/*.pyo @@ -59,6 +60,7 @@ if [ -f %{_datadir}/%{name}/gitprompt.sh ]; then # Set config variables first GIT_PROMPT_ONLY_IN_REPO=1 + GIT_PROMPT_THEME=Default source %{_datadir}/%{name}/gitprompt.sh fi %{END_TOKEN} From 5496b4cdb2412f8c5758ac55485f9fca9aefde95 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 11 Oct 2014 21:22:30 +0200 Subject: [PATCH 64/99] updated homebrew formula --- bash-git-prompt.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bash-git-prompt.rb b/bash-git-prompt.rb index 528d80d..48c1ded 100644 --- a/bash-git-prompt.rb +++ b/bash-git-prompt.rb @@ -2,19 +2,24 @@ require "formula" class BashGitPrompt < Formula homepage "https://github.com/magicmonty/bash-git-prompt" - url "https://github.com/magicmonty/bash-git-prompt/archive/2.1.tar.gz" - sha1 "9bd29dc2aa4859d2f4c0736cb26cc177de9c1274" + url "https://github.com/magicmonty/bash-git-prompt/archive/2.3.tar.gz" + sha1 "a4e692ef33b691724df6ac9582c204d31dbb853a" head "https://github.com/magicmonty/bash-git-prompt.git" def install - share.install "./gitprompt.sh", "./gitprompt.fish", "./git-prompt-help.sh", - "./git-prompt-colors.sh", "gitstatus.sh", "prompt-colors.sh" + share.install "gitprompt.sh", "gitprompt.fish", "git-prompt-help.sh", + "gitstatus.sh", "prompt-colors.sh" + + (share/"themes").install Dir["themes/*.bgptheme"], "themes/Custom.bgptemplate" doc.install "README.md" end def caveats; <<-EOS.undent You should add the following to your .bashrc (or equivalent): - source #{opt_share}/gitprompt.sh + if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then + GIT_PROMPT_THEME=Default + source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" + fi EOS end end From 222a49bcfc6fcc74f26ffa8f058c4fc32e580869 Mon Sep 17 00:00:00 2001 From: Dennis Xiloj Date: Fri, 17 Oct 2014 03:57:32 -0600 Subject: [PATCH 65/99] FIX GIT_PROMPT_ONLY_IN_REPO=1 should honor whatever previus prompt was --- gitprompt.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 1e3e691..69dc207 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -279,13 +279,37 @@ function setLastCommandState() { GIT_PROMPT_LAST_COMMAND_STATE=$? } +function we_are_on_repo() { + if [[ -e "$(git rev-parse --git-dir 2> /dev/null)" ]]; then + echo 1 + fi + echo 0 +} + +function update_old_git_prompt() { + local in_repo=$(we_are_on_repo) + if [[ $GIT_PROMPT_OLD_DIR_WAS_GIT = 0 ]]; then + OLD_GITPROMPT=$PS1 + fi + + GIT_PROMPT_OLD_DIR_WAS_GIT=$in_repo +} + function setGitPrompt() { + update_old_git_prompt + + local repo=`git rev-parse --show-toplevel 2> /dev/null` + if [[ ! -e "$repo" ]] && [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then + # we do not permit bash-git-prompt outside git repos, so nothing to do + PS1="$OLD_GITPROMPT" + return + fi + local EMPTY_PROMPT local __GIT_STATUS_CMD git_prompt_config - local repo=`git rev-parse --show-toplevel 2> /dev/null` if [[ ! -e "$repo" ]]; then PS1="$EMPTY_PROMPT" return @@ -440,10 +464,14 @@ function gp_install_prompt { else prompt_callback="prompt_callback_default" fi - + if [ -z "$OLD_GITPROMPT" ]; then OLD_GITPROMPT=$PS1 fi + + if [ -z "$GIT_PROMPT_OLD_DIR_WAS_GIT" ]; then + GIT_PROMPT_OLD_DIR_WAS_GIT=$(we_are_on_repo) + fi if [ -z "$PROMPT_COMMAND" ]; then PROMPT_COMMAND=setGitPrompt From 1893c825bf16aa126737ac1e75e4d3e75bf0e0c7 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 19 Oct 2014 14:07:25 +0200 Subject: [PATCH 66/99] Updated homebrew formula --- bash-git-prompt.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bash-git-prompt.rb b/bash-git-prompt.rb index 48c1ded..ab9a3bc 100644 --- a/bash-git-prompt.rb +++ b/bash-git-prompt.rb @@ -2,8 +2,8 @@ require "formula" class BashGitPrompt < Formula homepage "https://github.com/magicmonty/bash-git-prompt" - url "https://github.com/magicmonty/bash-git-prompt/archive/2.3.tar.gz" - sha1 "a4e692ef33b691724df6ac9582c204d31dbb853a" + url "https://github.com/magicmonty/bash-git-prompt/archive/2.3.1.tar.gz" + sha1 "c973bd8b86ac332d7310d79f0009844340b5999f" head "https://github.com/magicmonty/bash-git-prompt.git" def install @@ -17,7 +17,7 @@ class BashGitPrompt < Formula def caveats; <<-EOS.undent You should add the following to your .bashrc (or equivalent): if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then - GIT_PROMPT_THEME=Default + GIT_PROMPT_THEME=Default source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" fi EOS From cc97adfdb7f60107347a2ad2ed005d01d69b08fb Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Fri, 14 Nov 2014 20:28:34 +0100 Subject: [PATCH 67/99] There was _LAST_COMMAND_INDICATOR_ being printed in prompt output on root user Fixes #96 --- gitprompt.sh | 22 +++++++++++----------- themes/Default.bgptheme | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 69dc207..efcda1a 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -214,7 +214,7 @@ function git_prompt_config() fi # replace _LAST_COMMAND_STATE_ token with the actual state - LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR/_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_STATE}}" + LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR//_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_STATE}}" # Do this only once to define PROMPT_START and PROMPT_END @@ -254,14 +254,14 @@ function git_prompt_config() local ps="" if [[ -n "$VIRTUAL_ENV" ]]; then VENV=$(basename "${VIRTUAL_ENV}") - ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" + ps="${ps}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" fi if [[ -n "$CONDA_DEFAULT_ENV" ]]; then VENV=$(basename "${CONDA_DEFAULT_ENV}") - ps="${ps}${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" + ps="${ps}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" fi ps="$ps$PROMPT_START$($prompt_callback)$PROMPT_END" - EMPTY_PROMPT="${ps/_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" + EMPTY_PROMPT="${ps//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" fi # fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes @@ -361,11 +361,11 @@ function replaceSymbols() GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING=L fi - local VALUE=${1/_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}} - local VALUE1=${VALUE/_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}} - local VALUE2=${VALUE1/_NO_REMOTE_TRACKING_/${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING}} + local VALUE=${1//_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}} + local VALUE1=${VALUE//_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}} + local VALUE2=${VALUE1//_NO_REMOTE_TRACKING_/${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING}} - echo ${VALUE2/_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} + echo ${VALUE2//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} } function updatePrompt() { @@ -438,12 +438,12 @@ function updatePrompt() { NEW_PROMPT="" if [[ -n "$VIRTUAL_ENV" ]]; then VENV=$(basename "${VIRTUAL_ENV}") - NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" + NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" fi if [[ -n "$CONDA_DEFAULT_ENV" ]]; then VENV=$(basename "${CONDA_DEFAULT_ENV}") - NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV/_VIRTUALENV_/${VENV}}" + NEW_PROMPT="$NEW_PROMPT${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" fi NEW_PROMPT="$NEW_PROMPT$PROMPT_START$($prompt_callback)$STATUS$PROMPT_END" @@ -451,7 +451,7 @@ function updatePrompt() { NEW_PROMPT="$EMPTY_PROMPT" fi - PS1="${NEW_PROMPT/_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" + PS1="${NEW_PROMPT//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" } function prompt_callback_default { diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index d415eaf..b37b0e3 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -67,7 +67,7 @@ define_undefined_git_prompt_colors() { # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"; fi - if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}"; fi + if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ "; fi if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # "; fi From 7855e77e40d626c86d6ae7024d1ffc98c288f0e6 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Fri, 14 Nov 2014 21:38:43 +0100 Subject: [PATCH 68/99] .git was being touched continuously Fixes #97 --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 601e4cf..c5716e8 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -38,7 +38,7 @@ staged_files=`git diff --staged --name-status` num_changed=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` )) num_conflicts=`count_lines "$staged_files" U` num_staged=$(( `all_lines "$staged_files"` - num_conflicts )) -num_untracked=`git status -s -uall | grep -c "^??"` +num_untracked=`GIT_INDEX_FILE=/tmp/bash_git_prompt_index git status -s -uall | grep -c "^??"` if [[ -n "$GIT_PROMPT_IGNORE_STASH" ]]; then num_stashed=0 else From 58d02f4e9a35aafa6c73323f51aed26da468a6e0 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Fri, 14 Nov 2014 21:52:45 +0100 Subject: [PATCH 69/99] updated home-brew formula --- bash-git-prompt.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash-git-prompt.rb b/bash-git-prompt.rb index ab9a3bc..a63ea39 100644 --- a/bash-git-prompt.rb +++ b/bash-git-prompt.rb @@ -16,9 +16,9 @@ class BashGitPrompt < Formula def caveats; <<-EOS.undent You should add the following to your .bashrc (or equivalent): - if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then + if [ -f "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" ]; then GIT_PROMPT_THEME=Default - source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" + source "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" fi EOS end From f993391f2fef45749cc74a01a6e8589e808571a6 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 15 Nov 2014 07:59:44 +0100 Subject: [PATCH 70/99] Revert ".git was being touched continuously" This reverts commit 7855e77e40d626c86d6ae7024d1ffc98c288f0e6. --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index c5716e8..601e4cf 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -38,7 +38,7 @@ staged_files=`git diff --staged --name-status` num_changed=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` )) num_conflicts=`count_lines "$staged_files" U` num_staged=$(( `all_lines "$staged_files"` - num_conflicts )) -num_untracked=`GIT_INDEX_FILE=/tmp/bash_git_prompt_index git status -s -uall | grep -c "^??"` +num_untracked=`git status -s -uall | grep -c "^??"` if [[ -n "$GIT_PROMPT_IGNORE_STASH" ]]; then num_stashed=0 else From d81ea1d3a83e570a31ecc350cf1aa447409a2f29 Mon Sep 17 00:00:00 2001 From: Tobias Schottdorf Date: Sat, 15 Nov 2014 10:13:28 +0100 Subject: [PATCH 71/99] replace `git status` by `git ls-files ...` to avoid touching .git --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 601e4cf..173a966 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -38,7 +38,7 @@ staged_files=`git diff --staged --name-status` num_changed=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` )) num_conflicts=`count_lines "$staged_files" U` num_staged=$(( `all_lines "$staged_files"` - num_conflicts )) -num_untracked=`git status -s -uall | grep -c "^??"` +num_untracked=`git ls-files --others --exclude-standard | wc -l` if [[ -n "$GIT_PROMPT_IGNORE_STASH" ]]; then num_stashed=0 else From 050bc86d54b50df12c92351cc5f0b6be69c69595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Zaj=C4=85czkowski?= Date: Sun, 30 Nov 2014 20:26:44 +0100 Subject: [PATCH 72/99] Add info about L symbol to README 3 questions about that in a few months. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3735b5b..038ced1 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ The symbols are as follows: - ``↑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 :-) From c0510cf2fa5da151cbde508cde3c77fd1cb0a34f Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 3 Jan 2015 09:39:58 +0100 Subject: [PATCH 73/99] GIT_PROMPT_IGNORE_STASH was broken. Fixes #106 --- gitprompt.sh | 1 + gitstatus.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index efcda1a..3b07956 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -378,6 +378,7 @@ function updatePrompt() { git_prompt_config + export __GIT_PROMPT_IGNORE_STASH=${GIT_PROMPT_IGNORE_STASH} local -a GitStatus GitStatus=($("$__GIT_STATUS_CMD" 2>/dev/null)) diff --git a/gitstatus.sh b/gitstatus.sh index 173a966..267db45 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -39,7 +39,7 @@ num_changed=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` )) num_conflicts=`count_lines "$staged_files" U` num_staged=$(( `all_lines "$staged_files"` - num_conflicts )) num_untracked=`git ls-files --others --exclude-standard | wc -l` -if [[ -n "$GIT_PROMPT_IGNORE_STASH" ]]; then +if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then num_stashed=0 else num_stashed=`git stash list | wc -l` From 709b29c3fccde7380a9fd6a954ae65aa28637602 Mon Sep 17 00:00:00 2001 From: Jack Gargasz Date: Thu, 15 Jan 2015 15:47:57 +1100 Subject: [PATCH 74/99] New Single_line theme. --- themes/Single_line.bgptheme | 94 +++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 themes/Single_line.bgptheme diff --git a/themes/Single_line.bgptheme b/themes/Single_line.bgptheme new file mode 100644 index 0000000..f421a40 --- /dev/null +++ b/themes/Single_line.bgptheme @@ -0,0 +1,94 @@ +# This is an alternative approach. Single line in git repo. + +unset_git_prompt_colors() { + unset Time12a + unset PathShort + unset GIT_PROMPT_PREFIX + unset GIT_PROMPT_SUFFIX + unset GIT_PROMPT_SEPARATOR + unset GIT_PROMPT_BRANCH + unset GIT_PROMPT_STAGED + unset GIT_PROMPT_CONFLICTS + unset GIT_PROMPT_CHANGED + unset GIT_PROMPT_REMOTE + unset GIT_PROMPT_UNTRACKED + unset GIT_PROMPT_STASHED + unset GIT_PROMPT_CLEAN + unset GIT_PROMPT_COMMAND_OK + unset GIT_PROMPT_COMMAND_FAIL + unset GIT_PROMPT_VIRTUALENV + unset GIT_PROMPT_START_USER + unset GIT_PROMPT_START_ROOT + unset GIT_PROMPT_END_USER + unset GIT_PROMPT_END_ROOT + unset GIT_PROMPT_SYMBOLS_AHEAD + unset GIT_PROMPT_SYMBOLS_BEHIND + unset GIT_PROMPT_SYMBOLS_PREHASH + unset GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING +} + +define_helpers() +{ + Time12a="\$(date +%H:%M)" + PathShort="\w"; +} + +define_undefined_git_prompt_colors() { + if [[ -z ${GIT_PROMPT_THEME_NAME} ]]; then GIT_PROMPT_THEME_NAME="Single_line"; fi + + # These are the color definitions used by gitprompt.sh + if [[ -z ${GIT_PROMPT_PREFIX} ]]; then GIT_PROMPT_PREFIX="["; fi # start of the git info string + if [[ -z ${GIT_PROMPT_SUFFIX} ]]; then GIT_PROMPT_SUFFIX="]"; fi # the end of the git info string + if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR="|"; fi # separates each item + + if [[ -z ${GIT_PROMPT_BRANCH} ]]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory + if [[ -z ${GIT_PROMPT_STAGED} ]]; then GIT_PROMPT_STAGED="${Red}●"; fi # the number of staged files/directories + if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS="${Red}✖ "; fi # the number of files in conflict + if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED="${Blue}✚ "; fi # the number of changed files + + if [[ -z ${GIT_PROMPT_REMOTE} ]]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind + if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED="${Cyan}…"; fi # the number of untracked files/dirs + if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED="${BoldBlue}⚑ "; fi # the number of stashed files/dir + if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN="${BoldGreen}✔"; fi # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 + if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘"; fi # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + if [[ -z ${GIT_PROMPT_VIRTUALENV} ]]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${Time12a}${ResetColor} ${BoldYellow}${PathShort}${ResetColor}"; fi + if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi + if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER="${ResetColor} $ "; fi + if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT="${ResetColor} # "; fi + + # Please do not add colors to these symbols + if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked +} + +# call only from theme file +reload_git_prompt_colors() { + if [[ "${GIT_PROMPT_THEME_NAME}" != $1 ]]; then + unset_git_prompt_colors + define_helpers + override_git_prompt_colors + define_undefined_git_prompt_colors + fi +} + +if [[ "${GIT_PROMPT_THEME}" == "Single_line" && "${GIT_PROMPT_THEME_NAME}" != "Single_line" ]]; then + define_helpers + define_undefined_git_prompt_colors +fi From 4a62ec8a4bc3f710f681f5687f6021b24ea83e23 Mon Sep 17 00:00:00 2001 From: Jack Gargasz Date: Mon, 19 Jan 2015 15:46:08 +1100 Subject: [PATCH 75/99] Fix for Single_line.bgptheme --- themes/Single_line.bgptheme | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/themes/Single_line.bgptheme b/themes/Single_line.bgptheme index f421a40..52de1fb 100644 --- a/themes/Single_line.bgptheme +++ b/themes/Single_line.bgptheme @@ -51,7 +51,7 @@ define_undefined_git_prompt_colors() { if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED="${BoldBlue}⚑ "; fi # the number of stashed files/dir if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN="${BoldGreen}✔"; fi # a colored flag indicating a "clean" repo - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ # will be replaced with the exit code of the last command # e.g. # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 @@ -61,21 +61,21 @@ define_undefined_git_prompt_colors() { if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘"; fi # indicator if the last command returned with an exit code of other than 0 # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with + # use the placeholder _VIRTUALENV_ will be replaced with # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) if [[ -z ${GIT_PROMPT_VIRTUALENV} ]]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi - + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${Time12a}${ResetColor} ${BoldYellow}${PathShort}${ResetColor}"; fi if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER="${ResetColor} $ "; fi - if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT="${ResetColor} # "; fi + if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT="${BoldRed} # "; fi # Please do not add colors to these symbols if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found - if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked } # call only from theme file From badef3b37da97b90869522c27395439d02d76dc0 Mon Sep 17 00:00:00 2001 From: Jack Gargasz Date: Mon, 19 Jan 2015 15:50:54 +1100 Subject: [PATCH 76/99] New theme Single_line_Ubuntu. Fix for PowerLine fonts. --- themes/Single_line_Ubuntu.bgptheme | 94 ++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 themes/Single_line_Ubuntu.bgptheme diff --git a/themes/Single_line_Ubuntu.bgptheme b/themes/Single_line_Ubuntu.bgptheme new file mode 100644 index 0000000..781c096 --- /dev/null +++ b/themes/Single_line_Ubuntu.bgptheme @@ -0,0 +1,94 @@ +# This is an alternative approach. Single line in git repo. + +unset_git_prompt_colors() { + unset Time12a + unset PathShort + unset GIT_PROMPT_PREFIX + unset GIT_PROMPT_SUFFIX + unset GIT_PROMPT_SEPARATOR + unset GIT_PROMPT_BRANCH + unset GIT_PROMPT_STAGED + unset GIT_PROMPT_CONFLICTS + unset GIT_PROMPT_CHANGED + unset GIT_PROMPT_REMOTE + unset GIT_PROMPT_UNTRACKED + unset GIT_PROMPT_STASHED + unset GIT_PROMPT_CLEAN + unset GIT_PROMPT_COMMAND_OK + unset GIT_PROMPT_COMMAND_FAIL + unset GIT_PROMPT_VIRTUALENV + unset GIT_PROMPT_START_USER + unset GIT_PROMPT_START_ROOT + unset GIT_PROMPT_END_USER + unset GIT_PROMPT_END_ROOT + unset GIT_PROMPT_SYMBOLS_AHEAD + unset GIT_PROMPT_SYMBOLS_BEHIND + unset GIT_PROMPT_SYMBOLS_PREHASH + unset GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING +} + +define_helpers() +{ + Time12a="\$(date +%H:%M)" + PathShort="\w"; +} + +define_undefined_git_prompt_colors() { + if [[ -z ${GIT_PROMPT_THEME_NAME} ]]; then GIT_PROMPT_THEME_NAME="Single_line_Ubuntu"; fi + + # These are the color definitions used by gitprompt.sh + if [[ -z ${GIT_PROMPT_PREFIX} ]]; then GIT_PROMPT_PREFIX="[ "; fi # start of the git info string + if [[ -z ${GIT_PROMPT_SUFFIX} ]]; then GIT_PROMPT_SUFFIX=" ]"; fi # the end of the git info string + if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR=" |"; fi # separates each item + + if [[ -z ${GIT_PROMPT_BRANCH} ]]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory + if [[ -z ${GIT_PROMPT_STAGED} ]]; then GIT_PROMPT_STAGED=" ${Red}●${ResetColor}"; fi # the number of staged files/directories + if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS=" ${Red}✖ ${ResetColor}"; fi # the number of files in conflict + if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED=" ${Blue}✚ ${ResetColor}"; fi # the number of changed files + + if [[ -z ${GIT_PROMPT_REMOTE} ]]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind + if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}"; fi # the number of untracked files/dirs + if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED=" ${BoldBlue}⚑ ${ResetColor}"; fi # the number of stashed files/dir + if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN=" ${BoldGreen}✔ ${ResetColor}"; fi # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 + if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘"; fi # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + if [[ -z ${GIT_PROMPT_VIRTUALENV} ]]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${Time12a}${ResetColor} ${BoldYellow}${PathShort}${ResetColor}"; fi + if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi + if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER="${ResetColor} $ "; fi + if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT="${BoldRed} # "; fi + + # Please do not add colors to these symbols + if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked +} + +# call only from theme file +reload_git_prompt_colors() { + if [[ "${GIT_PROMPT_THEME_NAME}" != $1 ]]; then + unset_git_prompt_colors + define_helpers + override_git_prompt_colors + define_undefined_git_prompt_colors + fi +} + +if [[ "${GIT_PROMPT_THEME}" == "Single_line_Ubuntu" && "${GIT_PROMPT_THEME_NAME}" != "Single_line_Ubuntu" ]]; then + define_helpers + define_undefined_git_prompt_colors +fi From 3437d1d470039418beeb8a30f3dd2b93ec9031b5 Mon Sep 17 00:00:00 2001 From: Asazello Date: Tue, 20 Jan 2015 09:15:07 +1100 Subject: [PATCH 77/99] Minor fixes and code cleanup in Single_line_Ubuntu theme. --- themes/Single_line_Ubuntu.bgptheme | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/themes/Single_line_Ubuntu.bgptheme b/themes/Single_line_Ubuntu.bgptheme index 781c096..2a42acd 100644 --- a/themes/Single_line_Ubuntu.bgptheme +++ b/themes/Single_line_Ubuntu.bgptheme @@ -1,4 +1,5 @@ # This is an alternative approach. Single line in git repo. +# Theme optimised for Terminus and PowerLine compatible fonts. unset_git_prompt_colors() { unset Time12a @@ -39,17 +40,17 @@ define_undefined_git_prompt_colors() { # These are the color definitions used by gitprompt.sh if [[ -z ${GIT_PROMPT_PREFIX} ]]; then GIT_PROMPT_PREFIX="[ "; fi # start of the git info string if [[ -z ${GIT_PROMPT_SUFFIX} ]]; then GIT_PROMPT_SUFFIX=" ]"; fi # the end of the git info string - if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR=" |"; fi # separates each item + if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR=" |"; fi # separates each item - if [[ -z ${GIT_PROMPT_BRANCH} ]]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory - if [[ -z ${GIT_PROMPT_STAGED} ]]; then GIT_PROMPT_STAGED=" ${Red}●${ResetColor}"; fi # the number of staged files/directories - if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS=" ${Red}✖ ${ResetColor}"; fi # the number of files in conflict - if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED=" ${Blue}✚ ${ResetColor}"; fi # the number of changed files + if [[ -z ${GIT_PROMPT_BRANCH} ]]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory + if [[ -z ${GIT_PROMPT_STAGED} ]]; then GIT_PROMPT_STAGED=" ${Red}●${ResetColor}"; fi # the number of staged files/directories + if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS=" ${Red}✖ ${ResetColor}"; fi # the number of files in conflict + if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED=" ${Blue}✚ ${ResetColor}"; fi # the number of changed files - if [[ -z ${GIT_PROMPT_REMOTE} ]]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind - if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}"; fi # the number of untracked files/dirs - if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED=" ${BoldBlue}⚑ ${ResetColor}"; fi # the number of stashed files/dir - if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN=" ${BoldGreen}✔ ${ResetColor}"; fi # a colored flag indicating a "clean" repo + if [[ -z ${GIT_PROMPT_REMOTE} ]]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind + if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}"; fi # the number of untracked files/dirs + if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED=" ${BoldBlue}⚑ ${ResetColor}"; fi # the number of stashed files/dir + if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN=" ${BoldGreen}✔ ${ResetColor}"; fi # a colored flag indicating a "clean" repo # For the command indicator, the placeholder _LAST_COMMAND_STATE_ # will be replaced with the exit code of the last command @@ -58,7 +59,7 @@ define_undefined_git_prompt_colors() { # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 - if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘"; fi # indicator if the last command returned with an exit code of other than 0 + if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘"; fi # indicator if the last command returned with an exit code of other than 0 # template for displaying the current virtual environment # use the placeholder _VIRTUALENV_ will be replaced with @@ -66,15 +67,16 @@ define_undefined_git_prompt_colors() { if [[ -z ${GIT_PROMPT_VIRTUALENV} ]]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL - if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${Time12a}${ResetColor} ${BoldYellow}${PathShort}${ResetColor}"; fi + if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${Time12a}${ResetColor} ${Cyan}${PathShort}${ResetColor}"; fi + if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi - if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER="${ResetColor} $ "; fi - if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT="${BoldRed} # "; fi + if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER="${ResetColor} $ "; fi # Reset color for user + if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT="${BoldRed} # "; fi # Bright red for Root # Please do not add colors to these symbols - if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" - if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" - if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked } From fb4dbaa6454a820cab69d3d410473ac306b5d666 Mon Sep 17 00:00:00 2001 From: Asazello Date: Tue, 20 Jan 2015 09:17:45 +1100 Subject: [PATCH 78/99] Minor fixes and code cleanup in Single_line theme. --- themes/Single_line.bgptheme | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/themes/Single_line.bgptheme b/themes/Single_line.bgptheme index 52de1fb..b64e361 100644 --- a/themes/Single_line.bgptheme +++ b/themes/Single_line.bgptheme @@ -39,17 +39,17 @@ define_undefined_git_prompt_colors() { # These are the color definitions used by gitprompt.sh if [[ -z ${GIT_PROMPT_PREFIX} ]]; then GIT_PROMPT_PREFIX="["; fi # start of the git info string if [[ -z ${GIT_PROMPT_SUFFIX} ]]; then GIT_PROMPT_SUFFIX="]"; fi # the end of the git info string - if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR="|"; fi # separates each item + if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR="|"; fi # separates each item if [[ -z ${GIT_PROMPT_BRANCH} ]]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory if [[ -z ${GIT_PROMPT_STAGED} ]]; then GIT_PROMPT_STAGED="${Red}●"; fi # the number of staged files/directories - if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS="${Red}✖ "; fi # the number of files in conflict - if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED="${Blue}✚ "; fi # the number of changed files + if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS="${Red}✖ "; fi # the number of files in conflict + if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED="${Blue}✚ "; fi # the number of changed files if [[ -z ${GIT_PROMPT_REMOTE} ]]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind - if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED="${Cyan}…"; fi # the number of untracked files/dirs - if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED="${BoldBlue}⚑ "; fi # the number of stashed files/dir - if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN="${BoldGreen}✔"; fi # a colored flag indicating a "clean" repo + if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED="${Cyan}…"; fi # the number of untracked files/dirs + if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED="${BoldBlue}⚑ "; fi # the number of stashed files/dir + if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN="${BoldGreen}✔"; fi # a colored flag indicating a "clean" repo # For the command indicator, the placeholder _LAST_COMMAND_STATE_ # will be replaced with the exit code of the last command @@ -58,7 +58,7 @@ define_undefined_git_prompt_colors() { # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 - if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘"; fi # indicator if the last command returned with an exit code of other than 0 + if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘"; fi # indicator if the last command returned with an exit code of other than 0 # template for displaying the current virtual environment # use the placeholder _VIRTUALENV_ will be replaced with @@ -72,10 +72,10 @@ define_undefined_git_prompt_colors() { if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT="${BoldRed} # "; fi # Please do not add colors to these symbols - if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" - if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" - if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found - if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked + if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked } # call only from theme file From 4083a4b8d7ce83d110e608b63b460da26cfd5c29 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 24 Jan 2015 23:12:50 +0100 Subject: [PATCH 79/99] Show all untracked files in the repository instead of just from ./ on. --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 267db45..68d1a08 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -38,7 +38,7 @@ staged_files=`git diff --staged --name-status` num_changed=$(( `all_lines "$gitstatus"` - `count_lines "$gitstatus" U` )) num_conflicts=`count_lines "$staged_files" U` num_staged=$(( `all_lines "$staged_files"` - num_conflicts )) -num_untracked=`git ls-files --others --exclude-standard | wc -l` +num_untracked=`git ls-files --others --exclude-standard $(git rev-parse --show-cdup) | wc -l` if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then num_stashed=0 else From 0cebf28e091b3bab962df78436a18ec146c74efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Thu, 5 Feb 2015 10:21:35 +0100 Subject: [PATCH 80/99] added openSUSE themes --- .../Single_line_NoExitState_openSUSE.bgptheme | 19 +++++++++++++++++++ themes/Single_line_openSUSE.bgptheme | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 themes/Single_line_NoExitState_openSUSE.bgptheme create mode 100644 themes/Single_line_openSUSE.bgptheme diff --git a/themes/Single_line_NoExitState_openSUSE.bgptheme b/themes/Single_line_NoExitState_openSUSE.bgptheme new file mode 100644 index 0000000..e3580d7 --- /dev/null +++ b/themes/Single_line_NoExitState_openSUSE.bgptheme @@ -0,0 +1,19 @@ +# This is a theme for gitprompt.sh, +# it uses the default openSUSE bash prompt style + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line_NoExitState_openSUSE" + GIT_PROMPT_BRANCH="${Cyan}" + GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}" + GIT_PROMPT_CHANGED="${Yellow}✚ " + GIT_PROMPT_STAGED="${Magenta}●" + + GIT_PROMPT_START_USER="\u@\h:\w" + GIT_PROMPT_START_ROOT="${BoldRed}\h:\w" + + GIT_PROMPT_END_USER="> " + GIT_PROMPT_END_ROOT=" # ${ResetColor}" +} + +reload_git_prompt_colors "Single_line_NoExitState_openSUSE" + diff --git a/themes/Single_line_openSUSE.bgptheme b/themes/Single_line_openSUSE.bgptheme new file mode 100644 index 0000000..396006a --- /dev/null +++ b/themes/Single_line_openSUSE.bgptheme @@ -0,0 +1,19 @@ +# This is a theme for gitprompt.sh, +# it uses the default openSUSE bash prompt style with exit status + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line_openSUSE" + GIT_PROMPT_BRANCH="${Cyan}" + GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}" + GIT_PROMPT_CHANGED="${Yellow}✚ " + GIT_PROMPT_STAGED="${Magenta}●" + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${ResetColor}\u@\h:\w" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${BoldRed}\h:\w" + + GIT_PROMPT_END_USER="${ResetColor}> " + GIT_PROMPT_END_ROOT=" # ${ResetColor}" +} + +reload_git_prompt_colors "Single_line_openSUSE" + From 350d6c2a2ecd4fee2906e2a49fc0067fd1870d62 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Mon, 9 Feb 2015 21:48:43 +0100 Subject: [PATCH 81/99] Updated homebrew formula --- bash-git-prompt.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash-git-prompt.rb b/bash-git-prompt.rb index a63ea39..9be0688 100644 --- a/bash-git-prompt.rb +++ b/bash-git-prompt.rb @@ -2,8 +2,8 @@ require "formula" class BashGitPrompt < Formula homepage "https://github.com/magicmonty/bash-git-prompt" - url "https://github.com/magicmonty/bash-git-prompt/archive/2.3.1.tar.gz" - sha1 "c973bd8b86ac332d7310d79f0009844340b5999f" + url "https://github.com/magicmonty/bash-git-prompt/archive/2.3.5.tar.gz" + sha1 "16e1a9ab0ac711de79fd3b823138c16fadb3d5de" head "https://github.com/magicmonty/bash-git-prompt.git" def install From 5762652b2544aa48a53929113af96f7664a4a424 Mon Sep 17 00:00:00 2001 From: Brent Redd Date: Mon, 27 Apr 2015 17:25:56 -0600 Subject: [PATCH 82/99] use double quotes to handle path with spaces --- gitprompt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 3b07956..9c56dec 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -52,7 +52,7 @@ function get_theme() local theme="" # use default theme, if theme was not found - for themefile in `ls $__GIT_PROMPT_DIR/themes`; do + for themefile in `ls "$__GIT_PROMPT_DIR/themes"`; do if [[ "${themefile}" = "${GIT_PROMPT_THEME}.bgptheme" ]]; then theme=$GIT_PROMPT_THEME fi @@ -83,7 +83,7 @@ function git_prompt_list_themes() git_prompt_dir get_theme - for themefile in `ls $__GIT_PROMPT_DIR/themes`; do + for themefile in `ls "$__GIT_PROMPT_DIR/themes"`; do local theme="$(basename $themefile .bgptheme)" if [[ "${GIT_PROMPT_THEME}" = "${theme}" ]]; then From 7ca0026b377aebf597cb6a0008f9f206817221ed Mon Sep 17 00:00:00 2001 From: Robert Meerman Date: Thu, 30 Apr 2015 20:42:48 +0100 Subject: [PATCH 83/99] _LAST_COMMAND_INDICATOR_ now displays symbolic names of signals --- gitprompt.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gitprompt.sh b/gitprompt.sh index 9c56dec..a534525 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -185,6 +185,24 @@ git_prompt_reset() { done } +# gp_format_exit_status RETVAL +# +# echos the symbolic signal name represented by RETVAL if the process was +# signalled, otherwise echos the original value of RETVAL + +gp_format_exit_status() { + local RETVAL="$1" + local SIGNAL + # Suppress STDERR in case RETVAL is not an integer (in such cases, RETVAL + # is echoed verbatim) + if [ "${RETVAL}" -gt 128 ] 2>/dev/null; then + SIGNAL=$(( ${RETVAL} - 128 )) + kill -l "${SIGNAL}" 2>/dev/null || echo "${RETVAL}" + else + echo "${RETVAL}" + fi +} + function git_prompt_config() { #Checking if root to change output @@ -214,6 +232,7 @@ function git_prompt_config() fi # replace _LAST_COMMAND_STATE_ token with the actual state + GIT_PROMPT_LAST_COMMAND_STATE=$(gp_format_exit_status ${GIT_PROMPT_LAST_COMMAND_STATE}) LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR//_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_STATE}}" # Do this only once to define PROMPT_START and PROMPT_END From 37b2001fc164a651b3eba7656089c65b487e8a23 Mon Sep 17 00:00:00 2001 From: krazedkrish Date: Thu, 7 May 2015 22:06:35 +0545 Subject: [PATCH 84/99] Added oh-my-zsh's crunch like theme --- themes/Crunch.bgptheme | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 themes/Crunch.bgptheme diff --git a/themes/Crunch.bgptheme b/themes/Crunch.bgptheme new file mode 100644 index 0000000..b3fca1b --- /dev/null +++ b/themes/Crunch.bgptheme @@ -0,0 +1,34 @@ +# This theme for gitprompt.sh is designed for dark color schemes +# it is clone of oh-my-zsh crunch theme style with exit status + +override_git_prompt_colors() { + if [ -e ~/.rvm/bin/rvm-prompt ]; then + RUBY_PROMPT='{$(~/.rvm/bin/rvm-prompt i v)}' + else + if which rbenv &> /dev/null; then + RUBY_PROMPT='{$(rbenv version | sed -e "s/ (set.*$//")}' + fi + fi + Time12a="\$(date +%H:%M)" + + GIT_PROMPT_THEME_NAME="Crunch" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_UNTRACKED="${Cyan}… " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " + + KERNEL_PROMPT='‹$(uname -r)›' + +GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_${White}{${Yellow}${Time12a}${White}}[${Magenta}${RUBY_PROMPT}${White}]${Cyan}${PathShort}${White}:" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER="\n${BoldBlue} ➭ ${ResetColor}" + GIT_PROMPT_END_ROOT="\n${BoldRed} # ${ResetColor}" + GIT_PROMPT_LEADING_SPACE=0 + GIT_PROMPT_PREFIX="${Green}[" + GIT_PROMPT_SUFFIX="${Green}]" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" +} + +reload_git_prompt_colors "Crunch" \ No newline at end of file From 93bd09c4cd8f8a445e3466157c52bd21ee946da5 Mon Sep 17 00:00:00 2001 From: krazedkrish Date: Thu, 7 May 2015 22:09:20 +0545 Subject: [PATCH 85/99] Added Single_line_Solarized theme --- themes/Crunch.bgptheme | 4 +- themes/Single_line_Solarized.bgptheme | 102 ++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 themes/Single_line_Solarized.bgptheme diff --git a/themes/Crunch.bgptheme b/themes/Crunch.bgptheme index b3fca1b..1841e19 100644 --- a/themes/Crunch.bgptheme +++ b/themes/Crunch.bgptheme @@ -23,8 +23,8 @@ override_git_prompt_colors() { GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_${White}{${Yellow}${Time12a}${White}}[${Magenta}${RUBY_PROMPT}${White}]${Cyan}${PathShort}${White}:" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER="\n${BoldBlue} ➭ ${ResetColor}" - GIT_PROMPT_END_ROOT="\n${BoldRed} # ${ResetColor}" + GIT_PROMPT_END_USER="${BoldBlue} ➭ ${ResetColor}" + GIT_PROMPT_END_ROOT="${BoldRed} # ${ResetColor}" GIT_PROMPT_LEADING_SPACE=0 GIT_PROMPT_PREFIX="${Green}[" GIT_PROMPT_SUFFIX="${Green}]" diff --git a/themes/Single_line_Solarized.bgptheme b/themes/Single_line_Solarized.bgptheme new file mode 100644 index 0000000..d44e0ea --- /dev/null +++ b/themes/Single_line_Solarized.bgptheme @@ -0,0 +1,102 @@ +# This is an alternative approach. Single line in git repo. +# Theme optimised for Terminus and PowerLine compatible fonts. +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# without the indicator of the last command state +# tweaked for Ubuntu terminal fonts + +unset_git_prompt_colors() { + unset Time12a + unset PathShort + unset GIT_PROMPT_PREFIX + unset GIT_PROMPT_SUFFIX + unset GIT_PROMPT_SEPARATOR + unset GIT_PROMPT_BRANCH + unset GIT_PROMPT_STAGED + unset GIT_PROMPT_CONFLICTS + unset GIT_PROMPT_CHANGED + unset GIT_PROMPT_REMOTE + unset GIT_PROMPT_UNTRACKED + unset GIT_PROMPT_STASHED + unset GIT_PROMPT_CLEAN + unset GIT_PROMPT_COMMAND_OK + unset GIT_PROMPT_COMMAND_FAIL + unset GIT_PROMPT_VIRTUALENV + unset GIT_PROMPT_START_USER + unset GIT_PROMPT_START_ROOT + unset GIT_PROMPT_END_USER + unset GIT_PROMPT_END_ROOT + unset GIT_PROMPT_SYMBOLS_AHEAD + unset GIT_PROMPT_SYMBOLS_BEHIND + unset GIT_PROMPT_SYMBOLS_PREHASH + unset GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING +} + +define_helpers() +{ + PathShort="${BoldBlue}\u:${Cyan}\W" +} + +define_undefined_git_prompt_colors() { + if [[ -z ${GIT_PROMPT_THEME_NAME} ]]; then GIT_PROMPT_THEME_NAME="Single_line_Solarized"; fi + + # These are the color definitions used by gitprompt.sh + if [[ -z ${GIT_PROMPT_PREFIX} ]]; then GIT_PROMPT_PREFIX="[ "; fi # start of the git info string + if [[ -z ${GIT_PROMPT_SUFFIX} ]]; then GIT_PROMPT_SUFFIX=" ]"; fi # the end of the git info string + if [[ -z ${GIT_PROMPT_SEPARATOR} ]]; then GIT_PROMPT_SEPARATOR=" |"; fi # separates each item + + if [[ -z ${GIT_PROMPT_BRANCH} ]]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory + if [[ -z ${GIT_PROMPT_STAGED} ]]; then GIT_PROMPT_STAGED=" ${Yellow}●${ResetColor}"; fi # the number of staged files/directories + if [[ -z ${GIT_PROMPT_CONFLICTS} ]]; then GIT_PROMPT_CONFLICTS=" ${Red}✖ ${ResetColor}"; fi # the number of files in conflict + if [[ -z ${GIT_PROMPT_CHANGED} ]]; then GIT_PROMPT_CHANGED=" ${Blue}✚ ${ResetColor}"; fi # the number of changed files + + if [[ -z ${GIT_PROMPT_REMOTE} ]]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind + if [[ -z ${GIT_PROMPT_UNTRACKED} ]]; then GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}"; fi # the number of untracked files/dirs + if [[ -z ${GIT_PROMPT_STASHED} ]]; then GIT_PROMPT_STASHED=" ${BoldMagenta}⚑ ${ResetColor}"; fi # the number of stashed files/dir + if [[ -z ${GIT_PROMPT_CLEAN} ]]; then GIT_PROMPT_CLEAN=" ${Green}✔ ${ResetColor}"; fi # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + if [[ -z ${GIT_PROMPT_COMMAND_OK} ]]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 + if [[ -z ${GIT_PROMPT_COMMAND_FAIL} ]]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘"; fi # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + if [[ -z ${GIT_PROMPT_VIRTUALENV} ]]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + if [[ -z ${GIT_PROMPT_START_USER} ]]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"; fi + + if [[ -z ${GIT_PROMPT_START_ROOT} ]]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi + if [[ -z ${GIT_PROMPT_END_USER} ]]; then GIT_PROMPT_END_USER="${BoldBlue} ➭ ${ResetColor}"; fi # Reset color for user + if [[ -z ${GIT_PROMPT_END_ROOT} ]]; then GIT_PROMPT_END_ROOT="${BoldRed} # "; fi # Bright red for Root + + # Please do not add colors to these symbols + if [[ -z ${GIT_PROMPT_SYMBOLS_AHEAD} ]]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_BEHIND} ]]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" + if [[ -z ${GIT_PROMPT_SYMBOLS_PREHASH} ]]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭"; fi # This symbol is written after the branch, if the branch is not tracked +} + +# call only from theme file +reload_git_prompt_colors() { + if [[ "${GIT_PROMPT_THEME_NAME}" != $1 ]]; then + unset_git_prompt_colors + define_helpers + override_git_prompt_colors + define_undefined_git_prompt_colors + fi +} + +if [[ "${GIT_PROMPT_THEME}" == "Single_line_Solarized" && "${GIT_PROMPT_THEME_NAME}" != "Single_line_Solarized" ]]; then + define_helpers + define_undefined_git_prompt_colors +fi + +overide_git_prompt_colors() { + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" +} \ No newline at end of file From 0a75bb8461fe1887dc4a3042137575d7df1eae0e Mon Sep 17 00:00:00 2001 From: krazedkrish Date: Thu, 7 May 2015 22:59:02 +0545 Subject: [PATCH 86/99] Added Solarized_Extravagant theme --- themes/Solarized_Extravagant.bgptheme | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 themes/Solarized_Extravagant.bgptheme diff --git a/themes/Solarized_Extravagant.bgptheme b/themes/Solarized_Extravagant.bgptheme new file mode 100644 index 0000000..2af807f --- /dev/null +++ b/themes/Solarized_Extravagant.bgptheme @@ -0,0 +1,36 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# tweaked for Ubuntu terminal fonts +# some modifications on colors +# added ruby prompt, and kernel version as well + +override_git_prompt_colors() { + if [ -e ~/.rvm/bin/rvm-prompt ]; then + RUBY_PROMPT='{$(~/.rvm/bin/rvm-prompt i v)}' + else + if which rbenv &> /dev/null; then + RUBY_PROMPT='{$(rbenv version | sed -e "s/ (set.*$//")}' + fi + fi + Time12a="\$(date +%H:%M:%S)" + + GIT_PROMPT_THEME_NAME="Solarized Extravagant" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_UNTRACKED="${Cyan}… " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " + + KERNEL_PROMPT='‹$(uname -r)›' + +GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${BoldBlueFg}${Time12a} ${Green}${KERNEL_PROMPT} ${Cyan}${RUBY_PROMPT} ${Yellow}${PathShort}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER="\n${BoldBlue} ➭ ${ResetColor}" + GIT_PROMPT_END_ROOT="\n${BoldRed} # ${ResetColor}" + GIT_PROMPT_LEADING_SPACE=1 + GIT_PROMPT_PREFIX="${Cyan}[" + GIT_PROMPT_SUFFIX="${Cyan}]" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" +} + +reload_git_prompt_colors "Solarized Extravagant" \ No newline at end of file From da368f4849bdd5e5e0df1cff0a9168d339ce1736 Mon Sep 17 00:00:00 2001 From: krazedkrish Date: Sat, 9 May 2015 15:59:31 +0545 Subject: [PATCH 87/99] Solarized_Extravagant theme gets ssh aware Solarized_Extravagant theme shows different symbol in prompt if the user has logged in through ssh --- themes/Solarized_Extravagant.bgptheme | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/themes/Solarized_Extravagant.bgptheme b/themes/Solarized_Extravagant.bgptheme index 2af807f..e5aef39 100644 --- a/themes/Solarized_Extravagant.bgptheme +++ b/themes/Solarized_Extravagant.bgptheme @@ -25,8 +25,13 @@ override_git_prompt_colors() { GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${BoldBlueFg}${Time12a} ${Green}${KERNEL_PROMPT} ${Cyan}${RUBY_PROMPT} ${Yellow}${PathShort}" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER="\n${BoldBlue} ➭ ${ResetColor}" - GIT_PROMPT_END_ROOT="\n${BoldRed} # ${ResetColor}" + if [ -n "$SSH_CLIENT" ]; then + GIT_PROMPT_END_USER="\n${BoldRed} ➤ ${ResetColor}" + GIT_PROMPT_END_ROOT="\n${BoldRed} » ${ResetColor}" + else + GIT_PROMPT_END_USER="\n${BoldBlue} ➭ ${ResetColor}" + GIT_PROMPT_END_ROOT="\n${BoldRed} # ${ResetColor}" + fi GIT_PROMPT_LEADING_SPACE=1 GIT_PROMPT_PREFIX="${Cyan}[" GIT_PROMPT_SUFFIX="${Cyan}]" From 39f94dd5556a638c74592d7cdf167792a9425d1f Mon Sep 17 00:00:00 2001 From: Michael Darling Date: Mon, 11 May 2015 22:49:26 -0400 Subject: [PATCH 88/99] get_prompt_help() failed sourcing themes/Default.bgptheme, unless called from the bash-git-prompt directory. Fixed by adding "{__GIT_PROMPT_DIR}/". --- git-prompt-help.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt-help.sh b/git-prompt-help.sh index d1fe751..bd1596e 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -4,7 +4,7 @@ git_prompt_help() { source ${__GIT_PROMPT_DIR}/prompt-colors.sh - source themes/Default.bgptheme + source ${__GIT_PROMPT_DIR}/themes/Default.bgptheme cat <|] From cf4971a86807c2f733757c3dc1243d35aa928bab Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Wed, 13 May 2015 14:49:53 +0200 Subject: [PATCH 89/99] The README contained a reference to the deprecated Python script Fixes #134 --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 038ced1..2d6f26b 100644 --- a/README.md +++ b/README.md @@ -187,12 +187,7 @@ If you use a custom theme in `.git-prompt-colors.sh`, please set `GIT_PROMPT_THE 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` or - `gitstatus.py`. Both scripts do the same thing, but the bash script is a tad - more quick, and is used by default. If you prefer the python script - (possibly because you have enhanced it), simply delete or change the name of - `gitstatus.sh`. - +- The current git repo information is obtained by the script `gitstatus.sh`. - You can define `prompt_callback` function to tweak your prompt dynamically. ```sh @@ -270,7 +265,6 @@ from scratch by following this procedure: --prefix=bash-git-prompt-${VER}/ \ HEAD \ -- *.sh \ - *.py \ *.fish \ README.md \ themes \ From 79de7691c75a1fe3e44b30f82915a47733fedf8b Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Wed, 13 May 2015 14:50:34 +0200 Subject: [PATCH 90/99] Delete gitstatus.py See #134, as the Python script is not supported anymore --- gitstatus.py | 124 --------------------------------------------------- 1 file changed, 124 deletions(-) delete mode 100755 gitstatus.py diff --git a/gitstatus.py b/gitstatus.py deleted file mode 100755 index f350409..0000000 --- a/gitstatus.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python -# -*- coding: UTF-8 -*- - -"""This module defines a Print function to use with python 2.x or 3.x., so we can use the prompt with older versions of Python too - -It's interface is that of python 3.0's print. See -http://docs.python.org/3.0/library/functions.html?highlight=print#print - -Shamelessly ripped from http://www.daniweb.com/software-development/python/code/217214/a-print-function-for-different-versions-of-python -""" - -__all__ = ["Print"] -import sys -try: - Print = eval("print") # python 3.0 case -except SyntaxError: - try: - D = dict() - exec("from __future__ import print_function\np=print", D) - Print = D["p"] # 2.6 case - del D - except SyntaxError: - del D - def Print(*args, **kwd): # 2.4, 2.5, define our own Print function - fout = kwd.get("file", sys.stdout) - w = fout.write - if args: - w(str(args[0])) - sep = kwd.get("sep", " ") - for a in args[1:]: - w(sep) - w(str(a)) - w(kwd.get("end", "\n")) - - -# change those symbols to whatever you prefer -symbols = {'ahead of': '↑·', 'behind': '↓·', 'prehash':':'} - -from subprocess import Popen, PIPE - -import sys -gitsym = Popen(['git', 'symbolic-ref', 'HEAD'], stdout=PIPE, stderr=PIPE) -branch, error = gitsym.communicate() - -error_string = error.decode('utf-8') - -if 'fatal: Not a git repository' in error_string: - sys.exit(0) - -branch = branch.decode('utf-8').strip()[11:] - -res, err = Popen(['git','diff','--name-status'], stdout=PIPE, stderr=PIPE).communicate() -err_string = err.decode('utf-8') - -if 'fatal' in err_string: - sys.exit(0) - -changed_files = [namestat[0] for namestat in res.splitlines()] -staged_files = [namestat[0] for namestat in Popen(['git','diff', '--staged','--name-status'], stdout=PIPE).communicate()[0].splitlines()] -nb_changed = len(changed_files) - changed_files.count('U') -nb_U = staged_files.count('U') -nb_staged = len(staged_files) - nb_U -staged = str(nb_staged) -conflicts = str(nb_U) -changed = str(nb_changed) -status_lines = Popen(['git','status','-s','-uall'],stdout=PIPE).communicate()[0].splitlines() -untracked_lines = [a for a in map(lambda s: s.decode('utf-8'), status_lines) if a.startswith("??")] -nb_untracked = len(untracked_lines) -untracked = str(nb_untracked) -stashes = Popen(['git','stash','list'],stdout=PIPE).communicate()[0].splitlines() -nb_stashed = len(stashes) -stashed = str(nb_stashed) - -if not nb_changed and not nb_staged and not nb_U and not nb_untracked and not nb_stashed: - clean = '1' -else: - clean = '0' - -remote = '' - -tag, tag_error = Popen(['git', 'describe', '--exact-match'], stdout=PIPE, stderr=PIPE).communicate() - -if not branch: # not on any branch - if tag: # if we are on a tag, print the tag's name - branch = tag - else: - branch = symbols['prehash']+ Popen(['git','rev-parse','--short','HEAD'], stdout=PIPE).communicate()[0].decode('utf-8')[:-1] -else: - remote_name = Popen(['git','config','branch.%s.remote' % branch], stdout=PIPE).communicate()[0].strip() - if remote_name: - merge_name = Popen(['git','config','branch.%s.merge' % branch], stdout=PIPE).communicate()[0].strip() - else: - remote_name = "origin" - merge_name = "refs/heads/%s" % branch - - if remote_name == '.': # local - remote_ref = merge_name - else: - remote_ref = 'refs/remotes/%s/%s' % (remote_name, merge_name[11:]) - revgit = Popen(['git', 'rev-list', '--left-right', '%s...HEAD' % remote_ref],stdout=PIPE, stderr=PIPE) - revlist = revgit.communicate()[0] - if revgit.poll(): # fallback to local - revlist = Popen(['git', 'rev-list', '--left-right', '%s...HEAD' % merge_name],stdout=PIPE, stderr=PIPE).communicate()[0] - behead = revlist.splitlines() - ahead = len([x for x in behead if x[0]=='>']) - behind = len(behead) - ahead - if behind: - remote += '%s%s' % (symbols['behind'], behind) - if ahead: - remote += '%s%s' % (symbols['ahead of'], ahead) - -if remote == "": - remote = '.' - -out = '\n'.join([ - str(branch), - str(remote), - staged, - conflicts, - changed, - untracked, - stashed, - clean]) -Print(out) From c1e0d50952475b5ab91be79cc89f133e03739f4a Mon Sep 17 00:00:00 2001 From: Hugo Sato Date: Sat, 23 May 2015 19:50:36 -0400 Subject: [PATCH 91/99] Help strings should use the themed variables --- git-prompt-help.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/git-prompt-help.sh b/git-prompt-help.sh index bd1596e..40e98cd 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -6,7 +6,7 @@ git_prompt_help() { source ${__GIT_PROMPT_DIR}/prompt-colors.sh source ${__GIT_PROMPT_DIR}/themes/Default.bgptheme cat <|] +The git prompt format is ${GIT_PROMPT_PREFIX}${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_SUFFIX} BRANCH is a branch name, such as "master" or "stage", a tag name, or commit hash prefixed with ':'. @@ -14,18 +14,18 @@ hash prefixed with ':'. 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}↑·N${ResetColor} - ahead of remote by N commits - ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}↓·N${ResetColor} - behind remote by N commits - ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}↓·M↑·N${ResetColor} - branches diverged, other by M commits, yours by N commits + ${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 LOCALSTATUS is one of the following: - ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean - ${GIT_PROMPT_STAGED} N${ResetColor} - N staged files - ${GIT_PROMPT_CONFLICTS} N${ResetColor} - N conflicted files - ${GIT_PROMPT_CHANGED} N${ResetColor} - N changed but *unstaged* files - ${GIT_PROMPT_UNTRACKED} N${ResetColor} - N untracked files - ${GIT_PROMPT_STASHED} N${ResetColor} - N stash entries + ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean + ${GIT_PROMPT_STAGED}N${ResetColor} - N staged files + ${GIT_PROMPT_CONFLICTS}N${ResetColor} - N conflicted files + ${GIT_PROMPT_CHANGED}N${ResetColor} - N changed but *unstaged* files + ${GIT_PROMPT_UNTRACKED}N${ResetColor} - N untracked files + ${GIT_PROMPT_STASHED}N${ResetColor} - N stash entries See "git_prompt_examples" for examples. EOF From 9f91317c7c9044736bb3f7fd26bcf0f422be0372 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Wed, 27 May 2015 07:37:48 -0400 Subject: [PATCH 92/99] Fix Solaris compatibility Add a workaround for the lack of -mmin in Solarises find, check for gfind from opencsw and failing that use perl, which Solaris ships with and is widely available on many other systems. If neither a working find nor perl is available, print a warning and turn off remote status checking. Use eval in async_run to run the command, the old bash in Solaris 5.10 does not recognize the previous syntax. Use command -v instead of which to check for the existance of rbenv in the Crunch and Solarized_Extravagant themes. command -v is the POSIX-ly correct way to check for the existance of a command, and which does not set the exit code on Solaris. --- gitprompt.sh | 46 +++++++++++++++++++++++++-- themes/Crunch.bgptheme | 4 +-- themes/Solarized_Extravagant.bgptheme | 4 +-- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index a534525..e5a4c1d 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -3,7 +3,7 @@ function async_run() { { - $1 &> /dev/null + eval "$@" &> /dev/null }& } @@ -357,13 +357,55 @@ function setGitPrompt() { updatePrompt } +# some versions of find do not have -mmin +_have_find_mmin=1 + +function olderThanMinutes() { + local matches + local find_exit_code + + if [[ -z "$_find_command" ]]; then + if command -v gfind > /dev/null; then + _find_command=gfind + else + _find_command=find + fi + fi + + if [[ "$_have_find_mmin" = 1 ]]; then + matches=`"$_find_command" "$1" -mmin +"$2" 2> /dev/null` + find_exit_code="$?" + if [[ -n "$matches" ]]; then + return 0 + else + if [[ "$find_exit_code" != 0 ]]; then + _have_find_mmin=0 + else + return 1 + fi + fi + fi + + # try perl, solaris ships with perl + if command -v perl > /dev/null; then + perl -e '((time - (stat("'"$1"'"))[9]) / 60) > '"$2"' && exit(0) || exit(1)' + return "$?" + else + echo >&2 + echo "WARNING: neither a find that supports -mmin (such as GNU find) or perl is available, disabling remote status checking. Install GNU find as gfind or perl to enable this feature, or set GIT_PROMPT_FETCH_REMOTE_STATUS=0 to disable this warning." >&2 + echo >&2 + GIT_PROMPT_FETCH_REMOTE_STATUS=0 + return 1 + fi +} + function checkUpstream() { local GIT_PROMPT_FETCH_TIMEOUT git_prompt_config local FETCH_HEAD="$repo/.git/FETCH_HEAD" # Fech repo if local is stale for more than $GIT_FETCH_TIMEOUT minutes - if [[ ! -e "$FETCH_HEAD" || -e `find "$FETCH_HEAD" -mmin +$GIT_PROMPT_FETCH_TIMEOUT` ]] + if [[ ! -e "$FETCH_HEAD" ]] || olderThanMinutes "$FETCH_HEAD" "$GIT_PROMPT_FETCH_TIMEOUT" then if [[ -n $(git remote show) ]]; then ( diff --git a/themes/Crunch.bgptheme b/themes/Crunch.bgptheme index 1841e19..78b99a5 100644 --- a/themes/Crunch.bgptheme +++ b/themes/Crunch.bgptheme @@ -5,7 +5,7 @@ override_git_prompt_colors() { if [ -e ~/.rvm/bin/rvm-prompt ]; then RUBY_PROMPT='{$(~/.rvm/bin/rvm-prompt i v)}' else - if which rbenv &> /dev/null; then + if command -v rbenv > /dev/null; then RUBY_PROMPT='{$(rbenv version | sed -e "s/ (set.*$//")}' fi fi @@ -31,4 +31,4 @@ GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_${White}{${Yellow}${Time12a}${Whi GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" } -reload_git_prompt_colors "Crunch" \ No newline at end of file +reload_git_prompt_colors "Crunch" diff --git a/themes/Solarized_Extravagant.bgptheme b/themes/Solarized_Extravagant.bgptheme index e5aef39..f93c362 100644 --- a/themes/Solarized_Extravagant.bgptheme +++ b/themes/Solarized_Extravagant.bgptheme @@ -7,7 +7,7 @@ override_git_prompt_colors() { if [ -e ~/.rvm/bin/rvm-prompt ]; then RUBY_PROMPT='{$(~/.rvm/bin/rvm-prompt i v)}' else - if which rbenv &> /dev/null; then + if command -v rbenv > /dev/null; then RUBY_PROMPT='{$(rbenv version | sed -e "s/ (set.*$//")}' fi fi @@ -38,4 +38,4 @@ GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${BoldBlueFg}${Time12a} ${Green} GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" } -reload_git_prompt_colors "Solarized Extravagant" \ No newline at end of file +reload_git_prompt_colors "Solarized Extravagant" From 16b55272c40543a46193953ab75b4141990f29aa Mon Sep 17 00:00:00 2001 From: Alexander Peyser Date: Fri, 12 Jun 2015 14:03:38 +0200 Subject: [PATCH 93/99] Spec file tried to include non-existent python files --- bash-git-prompt.spec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bash-git-prompt.spec b/bash-git-prompt.spec index ab5f0a1..9ae7c9b 100644 --- a/bash-git-prompt.spec +++ b/bash-git-prompt.spec @@ -31,7 +31,7 @@ rm -rf %{buildroot} install -d 755 %{buildroot}%{_datadir}/%{name} install -pm 755 *.sh %{buildroot}%{_datadir}/%{name} -install -pm 755 *.py %{buildroot}%{_datadir}/%{name} +#install -pm 755 *.py %{buildroot}%{_datadir}/%{name} install -pm 755 *.fish %{buildroot}%{_datadir}/%{name} install -pm 644 README.md %{buildroot}%{_datadir}/%{name} install -d 755 %{buildroot}%{_datadir}/%{name}/themes @@ -39,8 +39,8 @@ install -pm 644 themes/*.bgptheme %{buildroot}%{_datadir}/%{name}/themes install -pm 644 themes/*.bgptemplate %{buildroot}%{_datadir}/%{name}/themes # never include compiled Python program -rm -fr %{buildroot}%{_datadir}/%{name}/*.pyo -rm -fr %{buildroot}%{_datadir}/%{name}/*.pyc +#rm -fr %{buildroot}%{_datadir}/%{name}/*.pyo +#rm -fr %{buildroot}%{_datadir}/%{name}/*.pyc %clean From fff05011c08034ac9b6b68601b97397f6ed4c1c6 Mon Sep 17 00:00:00 2001 From: Roy Golan Date: Mon, 22 Jun 2015 14:13:59 +0300 Subject: [PATCH 94/99] Simplify branch name extraction Use symbolic-ref --short to get the branch name without the refs/heads Signed-off-by: Roy Golan --- gitstatus.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 68d1a08..d167e90 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -19,13 +19,10 @@ if [ -z "${__GIT_PROMPT_DIR}" ]; then __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" fi -gitsym=`git symbolic-ref HEAD` +branch=`git symbolic-ref HEAD --short` # if "fatal: Not a git repo .., then exit -case "$gitsym" in fatal*) exit 0 ;; esac - -# the current branch is the tail end of the symbolic reference -branch="${gitsym##refs/heads/}" # get the basename after "refs/heads/" +case "$branch" in fatal*) exit 0 ;; esac gitstatus=`git diff --name-status 2>&1` From 281309a7b1e3055f65b38b095c20898a9c0bf09d Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Tue, 23 Jun 2015 10:32:09 +0200 Subject: [PATCH 95/99] Revert "Delete gitstatus.py" This reverts commit 79de7691c75a1fe3e44b30f82915a47733fedf8b. --- gitstatus.py | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100755 gitstatus.py diff --git a/gitstatus.py b/gitstatus.py new file mode 100755 index 0000000..f350409 --- /dev/null +++ b/gitstatus.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +"""This module defines a Print function to use with python 2.x or 3.x., so we can use the prompt with older versions of Python too + +It's interface is that of python 3.0's print. See +http://docs.python.org/3.0/library/functions.html?highlight=print#print + +Shamelessly ripped from http://www.daniweb.com/software-development/python/code/217214/a-print-function-for-different-versions-of-python +""" + +__all__ = ["Print"] +import sys +try: + Print = eval("print") # python 3.0 case +except SyntaxError: + try: + D = dict() + exec("from __future__ import print_function\np=print", D) + Print = D["p"] # 2.6 case + del D + except SyntaxError: + del D + def Print(*args, **kwd): # 2.4, 2.5, define our own Print function + fout = kwd.get("file", sys.stdout) + w = fout.write + if args: + w(str(args[0])) + sep = kwd.get("sep", " ") + for a in args[1:]: + w(sep) + w(str(a)) + w(kwd.get("end", "\n")) + + +# change those symbols to whatever you prefer +symbols = {'ahead of': '↑·', 'behind': '↓·', 'prehash':':'} + +from subprocess import Popen, PIPE + +import sys +gitsym = Popen(['git', 'symbolic-ref', 'HEAD'], stdout=PIPE, stderr=PIPE) +branch, error = gitsym.communicate() + +error_string = error.decode('utf-8') + +if 'fatal: Not a git repository' in error_string: + sys.exit(0) + +branch = branch.decode('utf-8').strip()[11:] + +res, err = Popen(['git','diff','--name-status'], stdout=PIPE, stderr=PIPE).communicate() +err_string = err.decode('utf-8') + +if 'fatal' in err_string: + sys.exit(0) + +changed_files = [namestat[0] for namestat in res.splitlines()] +staged_files = [namestat[0] for namestat in Popen(['git','diff', '--staged','--name-status'], stdout=PIPE).communicate()[0].splitlines()] +nb_changed = len(changed_files) - changed_files.count('U') +nb_U = staged_files.count('U') +nb_staged = len(staged_files) - nb_U +staged = str(nb_staged) +conflicts = str(nb_U) +changed = str(nb_changed) +status_lines = Popen(['git','status','-s','-uall'],stdout=PIPE).communicate()[0].splitlines() +untracked_lines = [a for a in map(lambda s: s.decode('utf-8'), status_lines) if a.startswith("??")] +nb_untracked = len(untracked_lines) +untracked = str(nb_untracked) +stashes = Popen(['git','stash','list'],stdout=PIPE).communicate()[0].splitlines() +nb_stashed = len(stashes) +stashed = str(nb_stashed) + +if not nb_changed and not nb_staged and not nb_U and not nb_untracked and not nb_stashed: + clean = '1' +else: + clean = '0' + +remote = '' + +tag, tag_error = Popen(['git', 'describe', '--exact-match'], stdout=PIPE, stderr=PIPE).communicate() + +if not branch: # not on any branch + if tag: # if we are on a tag, print the tag's name + branch = tag + else: + branch = symbols['prehash']+ Popen(['git','rev-parse','--short','HEAD'], stdout=PIPE).communicate()[0].decode('utf-8')[:-1] +else: + remote_name = Popen(['git','config','branch.%s.remote' % branch], stdout=PIPE).communicate()[0].strip() + if remote_name: + merge_name = Popen(['git','config','branch.%s.merge' % branch], stdout=PIPE).communicate()[0].strip() + else: + remote_name = "origin" + merge_name = "refs/heads/%s" % branch + + if remote_name == '.': # local + remote_ref = merge_name + else: + remote_ref = 'refs/remotes/%s/%s' % (remote_name, merge_name[11:]) + revgit = Popen(['git', 'rev-list', '--left-right', '%s...HEAD' % remote_ref],stdout=PIPE, stderr=PIPE) + revlist = revgit.communicate()[0] + if revgit.poll(): # fallback to local + revlist = Popen(['git', 'rev-list', '--left-right', '%s...HEAD' % merge_name],stdout=PIPE, stderr=PIPE).communicate()[0] + behead = revlist.splitlines() + ahead = len([x for x in behead if x[0]=='>']) + behind = len(behead) - ahead + if behind: + remote += '%s%s' % (symbols['behind'], behind) + if ahead: + remote += '%s%s' % (symbols['ahead of'], ahead) + +if remote == "": + remote = '.' + +out = '\n'.join([ + str(branch), + str(remote), + staged, + conflicts, + changed, + untracked, + stashed, + clean]) +Print(out) From e72fd9a41b9b685a46bc95192c67654709f1f160 Mon Sep 17 00:00:00 2001 From: corbosman Date: Sat, 25 Jul 2015 12:41:57 +0200 Subject: [PATCH 96/99] fix match for theme --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index e5a4c1d..6308ac5 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -52,7 +52,7 @@ function get_theme() local theme="" # use default theme, if theme was not found - for themefile in `ls "$__GIT_PROMPT_DIR/themes"`; do + for themefile in $(cd "$__GIT_PROMPT_DIR/themes" && echo *); do if [[ "${themefile}" = "${GIT_PROMPT_THEME}.bgptheme" ]]; then theme=$GIT_PROMPT_THEME fi From a550921e75be44ecb06a4acfa638ddebe99494d8 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 13 Aug 2015 19:45:50 +0200 Subject: [PATCH 97/99] Revert "Simplify branch name extraction" This reverts commit fff05011c08034ac9b6b68601b97397f6ed4c1c6. Fixes #146 --- gitstatus.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index d167e90..68d1a08 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -19,10 +19,13 @@ if [ -z "${__GIT_PROMPT_DIR}" ]; then __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" fi -branch=`git symbolic-ref HEAD --short` +gitsym=`git symbolic-ref HEAD` # if "fatal: Not a git repo .., then exit -case "$branch" in fatal*) exit 0 ;; esac +case "$gitsym" in fatal*) exit 0 ;; esac + +# the current branch is the tail end of the symbolic reference +branch="${gitsym##refs/heads/}" # get the basename after "refs/heads/" gitstatus=`git diff --name-status 2>&1` From 798667a7d5550b8e07739c4b2ea74ee762dcfa0b Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 13 Aug 2015 20:23:51 +0200 Subject: [PATCH 98/99] GIT_PROMPT_FETCH_TIMEOUT in .bashrc isn't be ignored anymore Fixes #121 --- gitprompt.sh | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index e5a4c1d..751c16a 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -43,14 +43,14 @@ function get_theme() if [[ "${GIT_PROMPT_THEME}" = "Custom" ]]; then GIT_PROMPT_THEME="Custom" __GIT_PROMPT_THEME_FILE=$CUSTOM_THEME_FILE - + if [[ ! (-r $__GIT_PROMPT_THEME_FILE) ]]; then GIT_PROMPT_THEME="Default" __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE fi else local theme="" - + # use default theme, if theme was not found for themefile in `ls "$__GIT_PROMPT_DIR/themes"`; do if [[ "${themefile}" = "${GIT_PROMPT_THEME}.bgptheme" ]]; then @@ -60,7 +60,7 @@ function get_theme() if [[ "${theme}" = "" ]]; then GIT_PROMPT_THEME="Default" - fi + fi __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/${GIT_PROMPT_THEME}.bgptheme" fi @@ -75,7 +75,7 @@ function git_prompt_load_theme() source "${__GIT_PROMPT_THEME_FILE}" } -function git_prompt_list_themes() +function git_prompt_list_themes() { local oldTheme local oldThemeFile @@ -89,7 +89,7 @@ function git_prompt_list_themes() if [[ "${GIT_PROMPT_THEME}" = "${theme}" ]]; then echoc ${Red} "*${theme}" else - echo $theme + echo $theme fi done @@ -187,13 +187,13 @@ git_prompt_reset() { # gp_format_exit_status RETVAL # -# echos the symbolic signal name represented by RETVAL if the process was +# echos the symbolic signal name represented by RETVAL if the process was # signalled, otherwise echos the original value of RETVAL gp_format_exit_status() { local RETVAL="$1" local SIGNAL - # Suppress STDERR in case RETVAL is not an integer (in such cases, RETVAL + # Suppress STDERR in case RETVAL is not an integer (in such cases, RETVAL # is echoed verbatim) if [ "${RETVAL}" -gt 128 ] 2>/dev/null; then SIGNAL=$(( ${RETVAL} - 128 )) @@ -284,7 +284,9 @@ function git_prompt_config() fi # fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes - GIT_PROMPT_FETCH_TIMEOUT=${1-5} + if [[ -z "$GIT_PROMPT_FETCH_TIMEOUT" ]]; then + GIT_PROMPT_FETCH_TIMEOUT="5" + fi if [[ -z "$__GIT_STATUS_CMD" ]] ; then # if GIT_STATUS_CMD not defined.. git_prompt_dir if ! gp_maybe_set_envar_to_path __GIT_STATUS_CMD "$__GIT_PROMPT_DIR/gitstatus.sh" ; then @@ -310,20 +312,20 @@ function update_old_git_prompt() { if [[ $GIT_PROMPT_OLD_DIR_WAS_GIT = 0 ]]; then OLD_GITPROMPT=$PS1 fi - + GIT_PROMPT_OLD_DIR_WAS_GIT=$in_repo } function setGitPrompt() { update_old_git_prompt - + local repo=`git rev-parse --show-toplevel 2> /dev/null` if [[ ! -e "$repo" ]] && [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then # we do not permit bash-git-prompt outside git repos, so nothing to do PS1="$OLD_GITPROMPT" return fi - + local EMPTY_PROMPT local __GIT_STATUS_CMD @@ -425,7 +427,7 @@ function replaceSymbols() local VALUE=${1//_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}} local VALUE1=${VALUE//_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}} local VALUE2=${VALUE1//_NO_REMOTE_TRACKING_/${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING}} - + echo ${VALUE2//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} } @@ -526,11 +528,11 @@ function gp_install_prompt { else prompt_callback="prompt_callback_default" fi - + if [ -z "$OLD_GITPROMPT" ]; then OLD_GITPROMPT=$PS1 fi - + if [ -z "$GIT_PROMPT_OLD_DIR_WAS_GIT" ]; then GIT_PROMPT_OLD_DIR_WAS_GIT=$(we_are_on_repo) fi From ac88ad47570a0ac4a44a8e0ca43183808215f12e Mon Sep 17 00:00:00 2001 From: Adron Hall Date: Sun, 16 Aug 2015 12:48:58 -0700 Subject: [PATCH 99/99] Extremelly minor change to installation README.md for OS-X. --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2d6f26b..9be4440 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ staged, changed, etc. # ATTENTION! Breaking changes! -**If you use this prompt already, please update your `.git-prompt-colors.sh`, +**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!** @@ -24,7 +24,7 @@ and call the function `reload_git_prompt_colors ` like follows:** ```sh override_git_prompt_colors() { GIT_PROMPT_THEME_NAME="Custom" # needed for reload optimization, should be unique - + # Place your overrides here ... } @@ -37,7 +37,7 @@ The advantage of this approach is, that you only need to specify the parts, that --- -**The variable `GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR` was replaced with a more general placeholder +**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 @@ -83,10 +83,10 @@ The symbols are as follows: - Run `brew update` -- Run `brew install bash-git-prompt` for the last stable release or `brew install --HEAD bash-git-prompt` for the +- 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 `~/.bashrc` as follows: +- Now you can source the file in your `~/.bash_profile` as follows: ```sh if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then @@ -114,7 +114,7 @@ git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt # Set config variables first GIT_PROMPT_ONLY_IN_REPO=1 - + # GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status # GIT_PROMPT_START=... # uncomment for custom prompt start sequence @@ -138,7 +138,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 []`. If the name of +This file can now be generated with the command `git_prompt_make_custom_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. @@ -157,7 +157,7 @@ A theme consists of a function `override_git_prompt_colors()` which defines at l ```sh override_git_prompt_colors() { GIT_PROMPT_THEME_NAME="Custom" # needed for reload optimization, should be unique - + # Place your overrides here ... } @@ -203,7 +203,7 @@ function prompt_callback { - 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. + `_LAST_COMMAND_INDICATOR_` in any of the prompt templates. It is now by default activated in the default theme: ```sh @@ -218,7 +218,7 @@ function prompt_callback { ```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