From e62452b81b02a5164d5642f3cd9bafc038dd52cf Mon Sep 17 00:00:00 2001 From: Vitaly Zdanevich Date: Tue, 26 Jul 2022 14:31:06 +0300 Subject: [PATCH 01/40] README: remove spaces that increase horisontal scroll On GitHub. --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8f7ecff7..8f0c8055 100644 --- a/README.md +++ b/README.md @@ -146,28 +146,28 @@ cp gitprompt.fish ~/.config/fish/functions/fish_prompt.fish ```sh - # Set config variables first - GIT_PROMPT_ONLY_IN_REPO=1 +# Set config variables first +GIT_PROMPT_ONLY_IN_REPO=1 - # GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status - # GIT_PROMPT_IGNORE_SUBMODULES=1 # uncomment to avoid searching for changed files in submodules - # GIT_PROMPT_WITH_VIRTUAL_ENV=0 # uncomment to avoid setting virtual environment infos for node/python/conda environments +# GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status +# GIT_PROMPT_IGNORE_SUBMODULES=1 # uncomment to avoid searching for changed files in submodules +# GIT_PROMPT_WITH_VIRTUAL_ENV=0 # uncomment to avoid setting virtual environment infos for node/python/conda environments - # GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch - # GIT_PROMPT_SHOW_UNTRACKED_FILES=normal # can be no, normal or all; determines counting of untracked files +# GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch +# GIT_PROMPT_SHOW_UNTRACKED_FILES=normal # can be no, normal or all; determines counting of untracked files - # GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=0 # uncomment to avoid printing the number of changed files +# GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=0 # uncomment to avoid printing the number of changed files - # GIT_PROMPT_STATUS_COMMAND=gitstatus_pre-1.7.10.sh # uncomment to support Git older than 1.7.10 +# GIT_PROMPT_STATUS_COMMAND=gitstatus_pre-1.7.10.sh # uncomment to support Git older than 1.7.10 - # GIT_PROMPT_START=... # uncomment for custom prompt start sequence - # GIT_PROMPT_END=... # uncomment for custom prompt end sequence +# GIT_PROMPT_START=... # uncomment for custom prompt start sequence +# GIT_PROMPT_END=... # uncomment for custom prompt end sequence - # as last entry source the gitprompt script - # GIT_PROMPT_THEME=Custom # use custom theme specified in file GIT_PROMPT_THEME_FILE (default ~/.git-prompt-colors.sh) - # GIT_PROMPT_THEME_FILE=~/.git-prompt-colors.sh - # GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme - source ~/.bash-git-prompt/gitprompt.sh +# as last entry source the gitprompt script +# GIT_PROMPT_THEME=Custom # use custom theme specified in file GIT_PROMPT_THEME_FILE (default ~/.git-prompt-colors.sh) +# GIT_PROMPT_THEME_FILE=~/.git-prompt-colors.sh +# GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme +source ~/.bash-git-prompt/gitprompt.sh ``` You can set the `GIT_PROMPT_SHOW_UNTRACKED_FILES` variable to `no` or `normal` to speed things up if you have lots of From d01583541de38119f436bb62e96175984795a648 Mon Sep 17 00:00:00 2001 From: Marco Gunnink Date: Thu, 6 Jan 2022 11:40:29 +0100 Subject: [PATCH 02/40] Use --no-optional-locks in gitstatus.sh to speed up prompt in large repositories --- gitstatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 7cbda63a..76ffb43c 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -36,7 +36,7 @@ else remote_url='.' fi -gitstatus=$( LC_ALL=C git status ${_ignore_submodules} --untracked-files="${__GIT_PROMPT_SHOW_UNTRACKED_FILES:-normal}" --porcelain --branch ) +gitstatus=$( LC_ALL=C git --no-optional-locks status ${_ignore_submodules} --untracked-files="${__GIT_PROMPT_SHOW_UNTRACKED_FILES:-normal}" --porcelain --branch ) # if the status is fatal, exit now [[ ! "${?}" ]] && exit 0 From 0eb0947955ccf2855dcef88ad48aaef1fbb5c188 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 30 Dec 2021 22:28:59 +0000 Subject: [PATCH 03/40] Fixes for Solarized_UserHost. Make username and host colors the same. I have no idea why I made them different in the first place. Tighten spacing. Change "@" char to bold bright white. Signed-off-by: Rafael Kitover --- themes/Solarized_UserHost.bgptheme | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/themes/Solarized_UserHost.bgptheme b/themes/Solarized_UserHost.bgptheme index 4eea2f18..aa3638a1 100644 --- a/themes/Solarized_UserHost.bgptheme +++ b/themes/Solarized_UserHost.bgptheme @@ -1,7 +1,9 @@ -# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes -# based on "Solarized Extravagant", with user@host on the second line and some things removed. +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes, but works great with any color scheme. +# Based on "Solarized Extravagant", with user@host on the second line and some things removed. function override_git_prompt_colors() { + local bold_bright_white=$(echo -e "\001\e[1;97m\002") + GIT_PROMPT_THEME_NAME='Solarized UserHost' GIT_PROMPT_STAGED="${Yellow}● " GIT_PROMPT_UNTRACKED="${Cyan}… " @@ -10,10 +12,10 @@ function override_git_prompt_colors() { GIT_PROMPT_COMMAND_OK="${Green}✔ " GIT_PROMPT_COMMAND_FAIL="${Red}✘ " - GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}" + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_${Yellow}${PathShort}" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER="\n${Blue}\\u${White}@${BoldBlue}\\h ${BoldRed} ➤ ${ResetColor} " - GIT_PROMPT_END_ROOT="\n${Blue}\\u${White}@${BoldBlue}\\h ${BoldRed} #️ ${ResetColor} " + GIT_PROMPT_END_USER="\n${BoldBlue}\\u${bold_bright_white}@${BoldBlue}\\h${BoldRed} ➤${ResetColor} " + GIT_PROMPT_END_ROOT="\n${BoldBlue}\\u${bold_bright_white}@${BoldBlue}\\h${BoldRed} #️ {ResetColor} " GIT_PROMPT_LEADING_SPACE=1 GIT_PROMPT_PREFIX="${Cyan}[" GIT_PROMPT_SUFFIX="${Cyan}]" From 14bf43a60132d59d922d5d6e964f38975d42304c Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 30 Dec 2021 22:29:55 +0000 Subject: [PATCH 04/40] Add new theme: Windows_UserHost. This theme is based on Solarized_UserHost and my posh-git theme for PowerShell which is here: https://github.com/rkitover/windows-dev-guide#set-up-powershell-profile Signed-off-by: Rafael Kitover --- themes/Windows_UserHost.bgptheme | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 themes/Windows_UserHost.bgptheme diff --git a/themes/Windows_UserHost.bgptheme b/themes/Windows_UserHost.bgptheme new file mode 100644 index 00000000..0fa0061f --- /dev/null +++ b/themes/Windows_UserHost.bgptheme @@ -0,0 +1,27 @@ +# Based on "Solarized UserHost" with no unicode chars and different +# colors. + +function override_git_prompt_colors() { + local light_blue=$(echo -e "\001\e[38;2;140;206;250m\002") + local red=$(echo -e "\001\e[38;2;220;20;60m\002") + local bold_bright_white=$(echo -e "\001\e[1;97m\002") + + GIT_PROMPT_THEME_NAME='Windows UserHost' + GIT_PROMPT_STAGED="${Yellow}* " + GIT_PROMPT_UNTRACKED="${Cyan}.. " + GIT_PROMPT_STASHED="${BoldMagenta}S " + GIT_PROMPT_CLEAN="${Green}v " + GIT_PROMPT_COMMAND_OK="${Green}v " + GIT_PROMPT_COMMAND_FAIL="${Red}x " + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_${Yellow}${PathShort}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER="\n${light_blue}\\u${bold_bright_white}@${ResetColor}${light_blue}\\h${red} >${ResetColor} " + GIT_PROMPT_END_ROOT="\n${light_blue}\\u${bold_bright_white}@${ResetColor}${light_blue}\\h${red} #${ResetColor} " + GIT_PROMPT_LEADING_SPACE=1 + GIT_PROMPT_PREFIX="${Cyan}[" + GIT_PROMPT_SUFFIX="${Cyan}]" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L" +} + +reload_git_prompt_colors 'Windows UserHost' From 955c90f06e87d4ab81453ac2c6fe984d7ca9f0fe Mon Sep 17 00:00:00 2001 From: Adam Dinwoodie Date: Wed, 29 Dec 2021 11:08:43 +0000 Subject: [PATCH 05/40] Export variables for changing output When deciding what bits of output should be included in the status line, the variables that configure this aren't exported, which means any relevant configuration changes don't work. Fixes #474. --- gitprompt.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 8f3a45d7..c0096ea9 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -487,12 +487,12 @@ function updatePrompt() { git_prompt_config - __GIT_PROMPT_IGNORE_STASH="${GIT_PROMPT_IGNORE_STASH:-0}" - __GIT_PROMPT_SHOW_UPSTREAM="${GIT_PROMPT_SHOW_UPSTREAM:-0}" - __GIT_PROMPT_IGNORE_SUBMODULES="${GIT_PROMPT_IGNORE_SUBMODULES:-0}" - __GIT_PROMPT_WITH_USERNAME_AND_REPO="${GIT_PROMPT_WITH_USERNAME_AND_REPO:-0}" + export __GIT_PROMPT_IGNORE_STASH="${GIT_PROMPT_IGNORE_STASH:-0}" + export __GIT_PROMPT_SHOW_UPSTREAM="${GIT_PROMPT_SHOW_UPSTREAM:-0}" + export __GIT_PROMPT_IGNORE_SUBMODULES="${GIT_PROMPT_IGNORE_SUBMODULES:-0}" + export __GIT_PROMPT_WITH_USERNAME_AND_REPO="${GIT_PROMPT_WITH_USERNAME_AND_REPO:-0}" export __GIT_PROMPT_SHOW_UNTRACKED_FILES="${GIT_PROMPT_SHOW_UNTRACKED_FILES-normal}" - local __GIT_PROMPT_SHOW_CHANGED_FILES_COUNT="${GIT_PROMPT_SHOW_CHANGED_FILES_COUNT:-1}" + export __GIT_PROMPT_SHOW_CHANGED_FILES_COUNT="${GIT_PROMPT_SHOW_CHANGED_FILES_COUNT:-1}" local GIT_INDEX_PRIVATE="$(createPrivateIndex)" #important to define GIT_INDEX_FILE as local: This way it only affects this function (and below) - even with the export afterwards From 034b2b10e377217a5002611ca7e9b6a2e7b75eb9 Mon Sep 17 00:00:00 2001 From: Alex Coleman <8428797+LordMailman@users.noreply.github.com> Date: Fri, 12 Mar 2021 11:42:49 -0500 Subject: [PATCH 06/40] Removed duplicate _LAST_COMMAND_INDICATOR_ --- themes/Custom.bgptemplate | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/themes/Custom.bgptemplate b/themes/Custom.bgptemplate index ac17c677..59debef5 100644 --- a/themes/Custom.bgptemplate +++ b/themes/Custom.bgptemplate @@ -1,6 +1,6 @@ # This is the custom theme template for gitprompt.sh -# These are the defaults from the "Default" theme +# 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" @@ -24,7 +24,7 @@ override_git_prompt_colors() { # 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_ + ## 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 @@ -34,7 +34,7 @@ override_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 ## 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) # GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " @@ -45,7 +45,7 @@ override_git_prompt_colors() { ## _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_START_ROOT="${GIT_PROMPT_START_USER}" # GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " # GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " @@ -53,7 +53,7 @@ override_git_prompt_colors() { # 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 + # GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L" # This symbol is written after the branch, if the branch is not tracked # branch name(s) that will use $GIT_PROMPT_MASTER_BRANCH color # To specify multiple branches, use From 5da0a40f6dc871c651ef49b6952b5e285cafe856 Mon Sep 17 00:00:00 2001 From: Andy Jack Date: Tue, 9 Feb 2021 17:49:30 -0500 Subject: [PATCH 07/40] Replace while read loop with a readarray --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index c0096ea9..db20cd22 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -500,7 +500,7 @@ function updatePrompt() { export GIT_INDEX_FILE="${GIT_INDEX_PRIVATE}" local -a git_status_fields - while IFS=$'\n' read -r line; do git_status_fields+=("${line}"); done < <("${__GIT_STATUS_CMD}" 2>/dev/null) + readarray -t git_status_fields < <("${__GIT_STATUS_CMD}" 2>/dev/null) export GIT_BRANCH=$(replaceSymbols "${git_status_fields[0]}") local GIT_REMOTE="$(replaceSymbols "${git_status_fields[1]}")" From 57ac5baeee24d84984722e5477b1e7469bede3e8 Mon Sep 17 00:00:00 2001 From: jcjf Date: Sun, 28 Jun 2020 22:11:17 +0800 Subject: [PATCH 08/40] Add HOME environment variable to git status call Allows git status take the global core.excludesFile into account. Otherwise, the reported number of untracked files is incorrect. --- gitstatus.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gitstatus.py b/gitstatus.py index bf1d1d95..e19d71da 100755 --- a/gitstatus.py +++ b/gitstatus.py @@ -13,6 +13,7 @@ # change those symbols to whatever you prefer symbols = {'ahead of': '↑·', 'behind': '↓·', 'prehash': ':'} +import os import sys import re from subprocess import Popen, PIPE @@ -73,7 +74,8 @@ def get_stash(): # `git status --porcelain --branch` can collect all information # branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind -po = Popen(['git', 'status', '--porcelain', '--branch'], env={'LC_ALL': 'C'}, stdout=PIPE, stderr=PIPE) +po = Popen(['git', 'status', '--porcelain', '--branch'], + env={'HOME': os.environ['HOME'], 'LC_ALL': 'C'}, stdout=PIPE, stderr=PIPE) stdout, stderr = po.communicate() if po.returncode != 0: sys.exit(0) # Not a git repository From d5052122bcd7c02f120347db1ae6c39031db6815 Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Thu, 20 Feb 2020 19:23:22 +0100 Subject: [PATCH 09/40] Update rpm spec. Clean up whitespace, fix source URL, license. --- bash-git-prompt.spec | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bash-git-prompt.spec b/bash-git-prompt.spec index 71efbdef..94a0efb5 100644 --- a/bash-git-prompt.spec +++ b/bash-git-prompt.spec @@ -1,15 +1,15 @@ %global START_TOKEN ### Generated by %{name} rpm package %global END_TOKEN ### Generated by %{name} rpm package -Name: bash-git-prompt -Version: 2.7.1 -Release: 1%{?dist} -Summary: Informative git prompt for bash and fish +Name: bash-git-prompt +Version: 2.7.1 +Release: 1%{?dist} +Summary: Informative git prompt for bash and fish -Group: Development/Tools -License: FreeBSD -URL: https://github.com/magicmonty/bash-git-prompt -Source0: https://github.com/magicmonty/%{name}/archive/%{name}-%{version}.tar.gz +Group: Development/Tools +License: BSD-2-Clause +URL: https://github.com/magicmonty/bash-git-prompt +Source0: https://github.com/magicmonty/%{name}/archive/%{version}/%{name}-%{version}.tar.gz Requires: git BuildArch: noarch From 1f32665fdf4ba1c47ba4fee6c14558dbd3808607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Skalski?= Date: Fri, 29 Nov 2019 19:44:30 +0100 Subject: [PATCH 10/40] Allow to coexist other PROMPT_COMMAND(s) relying on command exit status --- gitprompt.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gitprompt.sh b/gitprompt.sh index db20cd22..9041496a 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -303,6 +303,7 @@ function git_prompt_config() { function setLastCommandState() { GIT_PROMPT_LAST_COMMAND_STATE="${?}" + return ${GIT_PROMPT_LAST_COMMAND_STATE} } function we_are_on_repo() { From c9b5c73c988763d780df9bf9aac3e3c361ff3f87 Mon Sep 17 00:00:00 2001 From: guenthgr Date: Fri, 14 Oct 2022 07:24:47 +0200 Subject: [PATCH 11/40] Cleanup the readme --- README.md | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 8f0c8055..ad9ea555 100644 --- a/README.md +++ b/README.md @@ -9,39 +9,8 @@ A ``bash`` prompt that displays information about the current git repository. In particular the branch name, difference with remote branch, number of files staged, changed, etc. -(an original idea from this [blog post][]). - `gitstatus.sh` and `git-prompt-help.sh` added by [AKS](http://github.com/aks). -# ATTENTION! Breaking changes! - -**If you use this prompt already, please update your `.git-prompt-colors.sh`, -if you have one. It now contains a function named `define_git_prompt_colors()` or `override_git_prompt_colors()`!** - -**Please see the ``Custom.bgptemplate`` in the ``themes`` subdirectory of the installation directory!** - -**You can now also use the function `override_git_prompt_colors()`. It should define the variable `GIT_PROMPT_THEME_NAME` -and call the function `reload_git_prompt_colors ` like follows:** - -```sh -override_git_prompt_colors() { - GIT_PROMPT_THEME_NAME="Custom" # needed for reload optimization, should be unique - - # Place your overrides here - ... -} - -# load the theme -reload_git_prompt_colors "Custom" -``` - -The advantage of this approach is, that you only need to specify the parts, that are different to the Default theme. - ---- - -**The variable `GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR` was replaced with a more general placeholder -named ``_LAST_COMMAND_INDICATOR_``, which is replaced by the state of the last executed command. It is now activated by default.** - ## Examples The prompt may look like the following: @@ -75,7 +44,7 @@ The symbols are as follows: - Upstream branch - Shows the remote tracking branch - Disabled by default - - Enable by setting GIT_PROMPT_SHOW_UPSTREAM=1 + - Enable by setting `GIT_PROMPT_SHOW_UPSTREAM=1` - Branch Tracking Symbols - ``↑n``: ahead of remote by ``n`` commits - ``↓n``: behind remote by ``n`` commits @@ -121,7 +90,7 @@ fi ### install for the fish shell -- If you cloned the repo to a directory other then ~/.bash-git-prompt , set __GIT_PROMPT_DIR in ~/.config/fish/config.fish +- If you cloned the repo to a directory other then `~/.bash-git-prompt` , set `__GIT_PROMPT_DIR` in `~/.config/fish/config.fish` to that path - To install as an option in the fish_config GUI @@ -189,7 +158,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 the base theme is ommitted or the theme file is not found, then the Default theme is used. If you have already a custom -`.git-prompt-colors.sh` in your home directory, a error message will be shown. +`.git-prompt-colors.sh` in your home directory, an error message will be shown. You can display a list of available themes with `git_prompt_list_themes` (the current theme is highlighted) From 352aaf0273441dd2f46fb9e7c0b4bee194407ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Grill?= Date: Fri, 14 Oct 2022 09:27:54 +0200 Subject: [PATCH 12/40] Revert "Replace while read loop with a readarray" This reverts commit 5da0a40f6dc871c651ef49b6952b5e285cafe856. --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 9041496a..74593b47 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -501,7 +501,7 @@ function updatePrompt() { export GIT_INDEX_FILE="${GIT_INDEX_PRIVATE}" local -a git_status_fields - readarray -t git_status_fields < <("${__GIT_STATUS_CMD}" 2>/dev/null) + while IFS=$'\n' read -r line; do git_status_fields+=("${line}"); done < <("${__GIT_STATUS_CMD}" 2>/dev/null) export GIT_BRANCH=$(replaceSymbols "${git_status_fields[0]}") local GIT_REMOTE="$(replaceSymbols "${git_status_fields[1]}")" From a8e4ffaf139e9a76ec767612d611e8d7fc22503d Mon Sep 17 00:00:00 2001 From: Jake Tesler Date: Wed, 17 Jul 2019 13:08:44 -0700 Subject: [PATCH 13/40] Added GIT_PROMPT_SHOW_TRACKING flag to options --- gitprompt.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 74593b47..aae3de3f 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -355,9 +355,12 @@ function setGitPrompt() { OLD_GIT_PROMPT_IGNORE_SUBMODULES="${GIT_PROMPT_IGNORE_SUBMODULES}" unset GIT_PROMPT_IGNORE_SUBMODULES + OLD_GIT_PROMPT_SHOW_TRACKING=${GIT_PROMPT_SHOW_TRACKING} + unset GIT_PROMPT_SHOW_TRACKING + if [[ -e "${repo}/.bash-git-rc" ]]; then # The config file can only contain variable declarations on the form A_B=0 or G_P=all - local CONFIG_SYNTAX="^(FETCH_REMOTE_STATUS|GIT_PROMPT_SHOW_UNTRACKED_FILES|GIT_PROMPT_IGNORE_SUBMODULES|GIT_PROMPT_IGNORE)=[0-9a-z]+$" + local CONFIG_SYNTAX="^(FETCH_REMOTE_STATUS|GIT_PROMPT_SHOW_UNTRACKED_FILES|GIT_PROMPT_IGNORE_SUBMODULES|GIT_PROMPT_SHOW_TRACKING|GIT_PROMPT_IGNORE)=[0-9a-z]+$" if grep -q -v -E "${CONFIG_SYNTAX}" "${repo}/.bash-git-rc"; then echo ".bash-git-rc can only contain variable values on the form NAME=value. Ignoring file." >&2 else @@ -375,6 +378,11 @@ function setGitPrompt() { fi unset OLD_GIT_PROMPT_IGNORE_SUBMODULES + if [ -z "${GIT_PROMPT_SHOW_TRACKING}" ]; then + GIT_PROMPT_SHOW_TRACKING=${OLD_GIT_PROMPT_SHOW_TRACKING} + fi + unset OLD_GIT_PROMPT_SHOW_TRACKING + if [[ "${GIT_PROMPT_IGNORE-}" = 1 ]]; then PS1="${EMPTY_PROMPT}" return @@ -492,6 +500,7 @@ function updatePrompt() { export __GIT_PROMPT_SHOW_UPSTREAM="${GIT_PROMPT_SHOW_UPSTREAM:-0}" export __GIT_PROMPT_IGNORE_SUBMODULES="${GIT_PROMPT_IGNORE_SUBMODULES:-0}" export __GIT_PROMPT_WITH_USERNAME_AND_REPO="${GIT_PROMPT_WITH_USERNAME_AND_REPO:-0}" + export __GIT_PROMPT_SHOW_TRACKING=${GIT_PROMPT_SHOW_TRACKING:-1} export __GIT_PROMPT_SHOW_UNTRACKED_FILES="${GIT_PROMPT_SHOW_UNTRACKED_FILES-normal}" export __GIT_PROMPT_SHOW_CHANGED_FILES_COUNT="${GIT_PROMPT_SHOW_CHANGED_FILES_COUNT:-1}" @@ -504,9 +513,11 @@ function updatePrompt() { while IFS=$'\n' read -r line; do git_status_fields+=("${line}"); done < <("${__GIT_STATUS_CMD}" 2>/dev/null) export GIT_BRANCH=$(replaceSymbols "${git_status_fields[0]}") - local GIT_REMOTE="$(replaceSymbols "${git_status_fields[1]}")" - if [[ "." == "${GIT_REMOTE}" ]]; then - unset GIT_REMOTE + if [[ $__GIT_PROMPT_SHOW_TRACKING != "0" ]]; then + local GIT_REMOTE="$(replaceSymbols "${git_status_fields[1]}")" + if [[ "." == "${GIT_REMOTE}" ]]; then + unset GIT_REMOTE + fi fi local GIT_REMOTE_USERNAME_REPO="$(replaceSymbols "${git_status_fields[2]}")" if [[ "." == "${GIT_REMOTE_USERNAME_REPO}" ]]; then From 6d10abf2b77332dcb75ba4b91cc25c30f35368f4 Mon Sep 17 00:00:00 2001 From: Jake Tesler Date: Fri, 14 Oct 2022 09:57:38 -0700 Subject: [PATCH 14/40] Update var check for consistency --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index aae3de3f..2b853254 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -378,7 +378,7 @@ function setGitPrompt() { fi unset OLD_GIT_PROMPT_IGNORE_SUBMODULES - if [ -z "${GIT_PROMPT_SHOW_TRACKING}" ]; then + if [[ -z "${GIT_PROMPT_SHOW_TRACKING+x}" ]]; then GIT_PROMPT_SHOW_TRACKING=${OLD_GIT_PROMPT_SHOW_TRACKING} fi unset OLD_GIT_PROMPT_SHOW_TRACKING From 8241a18c2f0dc31b07f9990fe68ccb524abeb49b Mon Sep 17 00:00:00 2001 From: guenthgr Date: Mon, 17 Oct 2022 20:14:15 +0200 Subject: [PATCH 15/40] Support running bash tests --- .editorconfig | 12 ++++++++++++ tests/all-tests.sh | 14 ++++++++++++++ tests/base.sh | 18 ++++++++++++++++++ tests/test-prompt-command.sh | 22 ++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 .editorconfig create mode 100755 tests/all-tests.sh create mode 100644 tests/base.sh create mode 100755 tests/test-prompt-command.sh diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..c471b376 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.sh] +indent_size = 2 diff --git a/tests/all-tests.sh b/tests/all-tests.sh new file mode 100755 index 00000000..b44d34ba --- /dev/null +++ b/tests/all-tests.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )";) + +fail_count=0 + +for testfile in "$SCRIPT_DIR"/test-*.sh +do + echo "" + echo "######### $(basename $testfile) ################" + $testfile || ((fail_count++)) +done + +exit $fail_count diff --git a/tests/base.sh b/tests/base.sh new file mode 100644 index 00000000..443cdc72 --- /dev/null +++ b/tests/base.sh @@ -0,0 +1,18 @@ + +function run_test() { + test_function="$1" + + if [ -z "$test_function" ]; then + echo "Test function missing. Specify one." + exit 2 + fi + + echo "" + echo "--> Running $test_function" + if $test_function ; then + echo "++ Test successful" + else + echo "-- Test failed" + exit 1 + fi +} diff --git a/tests/test-prompt-command.sh b/tests/test-prompt-command.sh new file mode 100755 index 00000000..fc353cdc --- /dev/null +++ b/tests/test-prompt-command.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )";) +source "$SCRIPT_DIR/base.sh" + +function test_prompt_command_is_set() { + source "$SCRIPT_DIR/../gitprompt.sh" + + echo "$PROMPT_COMMAND" + [[ "$PROMPT_COMMAND" == "setLastCommandState;setGitPrompt" ]] +} + +function test_prompt_command_respecting_custom_function() { + PROMPT_COMMAND="some" + source "$SCRIPT_DIR/../gitprompt.sh" + + echo "$PROMPT_COMMAND" + [[ "$PROMPT_COMMAND" == "setLastCommandState;some;setGitPrompt" ]] +} + +run_test "test_prompt_command_is_set" +run_test "test_prompt_command_respecting_custom_function" From 21fcf1c0a7ee597954a8e8375b4d78a5874ab673 Mon Sep 17 00:00:00 2001 From: guenthgr Date: Mon, 17 Oct 2022 20:14:58 +0200 Subject: [PATCH 16/40] Refactor PROMPT_COMMAND setup --- gitprompt.sh | 72 +++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 2b853254..f6ff2586 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -667,45 +667,53 @@ function git_prompt_toggle() { return } -function gp_install_prompt { - if [[ -z "${OLD_GITPROMPT+x}" ]]; then - OLD_GITPROMPT=${PS1} +function make_prompt_command_clean() { + PROMPT_COMMAND="${PROMPT_COMMAND//$'\n'/;}" # convert all new lines to semi-colons + PROMPT_COMMAND="${PROMPT_COMMAND#\;}" # remove leading semi-colon + PROMPT_COMMAND="${PROMPT_COMMAND%% }" # remove trailing spaces + PROMPT_COMMAND="${PROMPT_COMMAND%\;}" # remove trailing semi-colon +} + +function add_prompt_command() { + local new_entry="$1" + local insert_before="$2" + + if [[ ";${PROMPT_COMMAND};" == *";${new_entry};"* ]]; then + return 0 fi - if [[ -z "${GIT_PROMPT_OLD_DIR_WAS_GIT+x}" ]]; then - GIT_PROMPT_OLD_DIR_WAS_GIT=$(we_are_on_repo) + if [ -z "$PROMPT_COMMAND" ]; then + PROMPT_COMMAND="$new_entry" + return 0 fi - if [[ -z "${PROMPT_COMMAND:+x}" ]]; then - PROMPT_COMMAND=setGitPrompt + if [ "$insert_before" == "true" ]; then + PROMPT_COMMAND="${new_entry};${PROMPT_COMMAND}" else - PROMPT_COMMAND="${PROMPT_COMMAND//$'\n'/;}" # convert all new lines to semi-colons - PROMPT_COMMAND="${PROMPT_COMMAND#\;}" # remove leading semi-colon - PROMPT_COMMAND="${PROMPT_COMMAND%% }" # remove trailing spaces - PROMPT_COMMAND="${PROMPT_COMMAND%\;}" # remove trailing semi-colon - - local new_entry="setGitPrompt" - case ";${PROMPT_COMMAND};" in - *";${new_entry};"*) - # echo "PROMPT_COMMAND already contains: $new_entry" - :;; - *) - PROMPT_COMMAND="${PROMPT_COMMAND};${new_entry}" - # echo "PROMPT_COMMAND does not contain: $new_entry" - ;; - esac + PROMPT_COMMAND="${PROMPT_COMMAND};${new_entry}" + fi +} + +function add_to_beginning_of_prompt_command() { + add_prompt_command "$1" "true" +} + +function add_to_end_of_prompt_command() { + add_prompt_command "$1" "false" +} + +function gp_install_prompt { + 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 - 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 + make_prompt_command_clean + add_to_end_of_prompt_command "setGitPrompt" + add_to_beginning_of_prompt_command "setLastCommandState" git_prompt_dir source "${__GIT_PROMPT_DIR}/git-prompt-help.sh" From 5184a89c2af1eb4f51e8dbafde61b30c2f965d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Skalski?= Date: Fri, 29 Nov 2019 22:56:29 +0100 Subject: [PATCH 17/40] Enhance git_prompt_help and example with real colors and markers Additional fix when ${GIT_PROMPT_PREFIX} or ${GIT_PROMPT_SUFFIX} contain color sequences git_prompt_help's formatting was wrong --- git-prompt-help.sh | 47 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/git-prompt-help.sh b/git-prompt-help.sh index ffa3da57..d7cea58f 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -5,11 +5,12 @@ git_prompt_help() { source "${__GIT_PROMPT_DIR}/prompt-colors.sh" source "${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + cat <${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_SUFFIX} +The git prompt format is ${GIT_PROMPT_PREFIX}${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_SUFFIX}${ResetColor} -BRANCH is a branch name, such as "master" or "stage", a tag name, or commit -hash prefixed with ':'. +BRANCH is a branch name, such as "${GIT_PROMPT_MASTER_BRANCH}master${ResetColor}" or "${GIT_PROMPT_BRANCH}stage${ResetColor}", a tag name, or commit +${GIT_PROMPT_SYMBOLS_PREHASH}hash${ResetColor} prefixed with '${GIT_PROMPT_SYMBOLS_PREHASH:-':'}${ResetColor}'. TRACKING indicates how the local branch differs from the remote branch. It can be empty, or one of: @@ -34,32 +35,50 @@ EOF help_git_prompt() { git_prompt_help ; } git_prompt_examples() { + + format_branch() { + case "$1" in + ${GIT_PROMPT_MASTER_BRANCHES}) + echo "${GIT_PROMPT_MASTER_BRANCH}$1${ResetColor}" + ;; + *) + echo "${GIT_PROMPT_BRANCH}$1${ResetColor}" + ;; + esac + } + local p="${GIT_PROMPT_PREFIX}" + local s="${GIT_PROMPT_SUFFIX}${ResetColor}" + cat < Date: Thu, 19 Dec 2019 12:14:56 +0100 Subject: [PATCH 18/40] git-help-examples-fixup: Some more minor tweaks in help and examples --- git-prompt-help.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-prompt-help.sh b/git-prompt-help.sh index d7cea58f..0b93950e 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -17,7 +17,7 @@ remote branch. It can be empty, or one of: ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${ResetColor} - ahead of remote by N commits ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - behind remote by M commits - ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - branches diverged, other by M commits, yours by N commits + ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}M${GIT_PROMPT_SYMBOLS_AHEAD}N${ResetColor} - branches diverged, other by M commits, yours by N commits LOCALSTATUS is one of the following: @@ -63,7 +63,7 @@ These are examples of the git prompt: ${p}`format_branch master`${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_STASHED}2${ResetColor}${s} - on branch "master", 2 stash entries - ${p}`format_branch experimental`${GIT_PROMPT_REMOTE}${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_SYMBOLS_AHEAD}2${GIT_PROMPT_SYMBOLS_BEHIND}3${ResetColor}${s} + ${p}`format_branch experimental`${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}2${GIT_PROMPT_SYMBOLS_AHEAD}3${ResetColor}${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_CLEAN}${ResetColor}${s} - on branch "experimental"; your branch has diverged by 3 commits, remote by 2 commits; the repository is otherwise clean From 4d02d6bb3628694db3370c404fa507a6f9b884ce Mon Sep 17 00:00:00 2001 From: guenthgr Date: Tue, 18 Oct 2022 07:36:51 +0200 Subject: [PATCH 19/40] Make the old prompt handling slighlty easier --- gitprompt.sh | 13 ++----------- tests/base.sh | 7 +++++++ tests/test-non-git-ps1.sh | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 11 deletions(-) create mode 100755 tests/test-non-git-ps1.sh diff --git a/gitprompt.sh b/gitprompt.sh index f6ff2586..25b5bcf1 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -315,12 +315,11 @@ function we_are_on_repo() { } function update_old_git_prompt() { - local in_repo=$(we_are_on_repo) - if [[ "${GIT_PROMPT_OLD_DIR_WAS_GIT}" = 0 ]]; then + if [[ "${GIT_PROMPT_OLD_DIR_WAS_GIT:-0}" = 0 ]]; then OLD_GITPROMPT="${PS1}" fi - GIT_PROMPT_OLD_DIR_WAS_GIT="${in_repo}" + GIT_PROMPT_OLD_DIR_WAS_GIT=$(we_are_on_repo) } function setGitPrompt() { @@ -703,14 +702,6 @@ function add_to_end_of_prompt_command() { } function gp_install_prompt { - 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 - make_prompt_command_clean add_to_end_of_prompt_command "setGitPrompt" add_to_beginning_of_prompt_command "setLastCommandState" diff --git a/tests/base.sh b/tests/base.sh index 443cdc72..effa22c4 100644 --- a/tests/base.sh +++ b/tests/base.sh @@ -16,3 +16,10 @@ function run_test() { exit 1 fi } + +function run_prompt_command() { + IFS=';' read -ra COMMANDS <<< "$PROMPT_COMMAND" + for cmd in "${COMMANDS[@]}"; do + $cmd + done +} diff --git a/tests/test-non-git-ps1.sh b/tests/test-non-git-ps1.sh new file mode 100755 index 00000000..f970e04c --- /dev/null +++ b/tests/test-non-git-ps1.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )";) +source "$SCRIPT_DIR/base.sh" + +REPO_ROOT="$SCRIPT_DIR/.." + +function test_original_prompt_is_restored() { + GIT_PROMPT_ONLY_IN_REPO=1 + + PS1="$" + + # Navigate outside the git repo + cd "$REPO_ROOT/.." + source "$SCRIPT_DIR/../gitprompt.sh" + run_prompt_command + + if [ "$PS1" != "$" ]; then + echo "PS1: $PS1 != \$" + return 1 + fi + + # Navigate back into the repo + cd "$REPO_ROOT" + run_prompt_command + if [ "$PS1" == "$" ]; then + echo "PS1: $PS1 == \$" + return 1 + fi + + # And navigate again outside the repo + cd "$REPO_ROOT/.." + run_prompt_command + if [ "$PS1" != "$" ]; then + echo "PS1: $PS1 != \$" + return 1 + fi +} + +run_test "test_original_prompt_is_restored" From 0e189456cb6bce35ea53b83992a15cfe1e251f0c Mon Sep 17 00:00:00 2001 From: guenthgr Date: Tue, 18 Oct 2022 08:25:53 +0200 Subject: [PATCH 20/40] Make getting the git prompt dir easier --- gitprompt.sh | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 25b5bcf1..134bc188 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -6,17 +6,10 @@ function async_run() { }& } -function git_prompt_dir() { - # assume the gitstatus.sh is in the same directory as this script +function set_git_prompt_dir() { # code thanks to http://stackoverflow.com/questions/59895 - if [[ -z "${__GIT_PROMPT_DIR:+x}" ]]; then - local SOURCE="${BASH_SOURCE[0]}" - while [[ -h "${SOURCE}" ]]; do - local DIR="$( command cd -P "$( dirname "${SOURCE}" )" && pwd )" - SOURCE="$(readlink "${SOURCE}")" - [[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}" - done - __GIT_PROMPT_DIR="$( command cd -P "$( dirname "${SOURCE}" )" && pwd )" + if [ -z "$__GIT_PROMPT_DIR" ]; then + __GIT_PROMPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) fi } @@ -87,7 +80,6 @@ function git_prompt_load_theme() { function git_prompt_list_themes() { git_prompt_load_colors - git_prompt_dir get_theme for themefile in "${__GIT_PROMPT_DIR}/themes/"*.bgptheme; do @@ -111,8 +103,6 @@ function git_prompt_make_custom_theme() { if [[ -r "${HOME}/.git-prompt-colors.sh" ]]; then echoc "${Red}" "You have already created a custom theme!" else - git_prompt_dir - local base="Default" if [[ -n "${1}" && -r "${__GIT_PROMPT_DIR}/themes/${1}.bgptheme" ]]; then base="${1}" @@ -156,7 +146,6 @@ function gp_set_file_var() { 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 gp_maybe_set_envar_to_path "${envar}" "${__GIT_PROMPT_DIR}/${file}" "${0##*/}/${file}" && return 0 fi return 1 @@ -210,7 +199,7 @@ gp_format_exit_status() { fi } -gp_format_username_repo() { +function gp_format_username_repo() { git config --get remote.origin.url | sed 's|^.*//||; s/.*@//; s/[^:/]\+[:/]//; s/.git$//' } @@ -292,7 +281,6 @@ function git_prompt_config() { GIT_PROMPT_FETCH_TIMEOUT="5" fi if [[ -z "${__GIT_STATUS_CMD:+x}" ]] ; then # if GIT_STATUS_CMD not defined.. - git_prompt_dir if ! gp_maybe_set_envar_to_path __GIT_STATUS_CMD "${__GIT_PROMPT_DIR}/${GIT_PROMPT_STATUS_COMMAND}" ; then echo 1>&2 "Cannot find ${GIT_PROMPT_STATUS_COMMAND}!" fi @@ -706,7 +694,7 @@ function gp_install_prompt { add_to_end_of_prompt_command "setGitPrompt" add_to_beginning_of_prompt_command "setLastCommandState" - git_prompt_dir + set_git_prompt_dir source "${__GIT_PROMPT_DIR}/git-prompt-help.sh" } From e433e4637dc7458d3a8eda8b8a755db2d851ddab Mon Sep 17 00:00:00 2001 From: Aharon Hacmon Date: Wed, 31 Jul 2019 15:43:48 +0300 Subject: [PATCH 21/40] Update Default.bgptheme Add space after the dot in staged indicator --- themes/Default.bgptheme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index a43a5f17..694ca4fa 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -43,7 +43,7 @@ define_undefined_git_prompt_colors() { if [ -z "${GIT_PROMPT_BRANCH+x}" ]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory if [ -z "${GIT_PROMPT_MASTER_BRANCH+x}" ]; then GIT_PROMPT_MASTER_BRANCH="${GIT_PROMPT_BRANCH}"; fi # used if the git branch that is active in the current directory is $GIT_PROMPT_MASTER_BRANCHES - if [ -z "${GIT_PROMPT_STAGED+x}" ]; then GIT_PROMPT_STAGED="${Red}●"; fi # the number of staged files/directories + if [ -z "${GIT_PROMPT_STAGED+x}" ]; then GIT_PROMPT_STAGED="${Red}● "; fi # the number of staged files/directories if [ -z "${GIT_PROMPT_CONFLICTS+x}" ]; then GIT_PROMPT_CONFLICTS="${Red}✖ "; fi # the number of files in conflict if [ -z "${GIT_PROMPT_CHANGED+x}" ]; then GIT_PROMPT_CHANGED="${Blue}✚ "; fi # the number of changed files From 82a1fd5e3525652798f2c668e81b0e274c554f90 Mon Sep 17 00:00:00 2001 From: "B. Modi" Date: Sun, 7 Apr 2019 19:39:43 -0700 Subject: [PATCH 22/40] Minimal chevron theme reload patch --- themes/Minimal_Chevron.bgptheme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/Minimal_Chevron.bgptheme b/themes/Minimal_Chevron.bgptheme index 12190559..2272337b 100644 --- a/themes/Minimal_Chevron.bgptheme +++ b/themes/Minimal_Chevron.bgptheme @@ -24,7 +24,7 @@ # [https://github.com/modib] ############################################################################## override_git_prompt_colors() { - GIT_PROMPT_THEME_NAME="Minimal_Time" + GIT_PROMPT_THEME_NAME="Minimal_Chevron" #Overrides the prompt_callback function used by bash-git-prompt function prompt_callback { @@ -69,4 +69,4 @@ override_git_prompt_colors() { } -reload_git_prompt_colors "Minimal_Time" +reload_git_prompt_colors "Minimal_Chevron" From af82e91f084ec7c7f6e7c76294f2ee8d286e339b Mon Sep 17 00:00:00 2001 From: Fabian Sandoval Saldias Date: Thu, 28 Nov 2019 11:52:15 +0100 Subject: [PATCH 23/40] Make venv position configurable. --- README.md | 1 + gitprompt.sh | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad9ea555..28d7ac2b 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ GIT_PROMPT_ONLY_IN_REPO=1 # GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status # GIT_PROMPT_IGNORE_SUBMODULES=1 # uncomment to avoid searching for changed files in submodules # GIT_PROMPT_WITH_VIRTUAL_ENV=0 # uncomment to avoid setting virtual environment infos for node/python/conda environments +# GIT_PROMPT_VIRTUAL_ENV_AFTER_PROMPT=1 # uncomment to place virtual environment infos between prompt and git status (instead of left to the prompt) # GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch # GIT_PROMPT_SHOW_UNTRACKED_FILES=normal # can be no, normal or all; determines counting of untracked files diff --git a/gitprompt.sh b/gitprompt.sh index 134bc188..f8ecd68b 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -269,7 +269,11 @@ function git_prompt_config() { if [[ "${GIT_PROMPT_ONLY_IN_REPO:-0}" == 1 ]]; then EMPTY_PROMPT="${OLD_GITPROMPT}" elif [[ "${GIT_PROMPT_WITH_VIRTUAL_ENV:-1}" == 1 ]]; then - local ps="$(gp_add_virtualenv_to_prompt)${PROMPT_START}$(${prompt_callback})${PROMPT_END}" + if [[ "${GIT_PROMPT_VIRTUAL_ENV_AFTER_PROMPT:-0}" == "0" ]]; then + local ps="$(gp_add_virtualenv_to_prompt)${PROMPT_START}$(${prompt_callback})${PROMPT_END}" + else + local ps="${PROMPT_START}$(${prompt_callback})$(gp_add_virtualenv_to_prompt)${PROMPT_END}" + fi EMPTY_PROMPT="${ps//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" else local ps="${PROMPT_START}$(${prompt_callback})${PROMPT_END}" @@ -590,7 +594,11 @@ function updatePrompt() { fi __add_status "${ResetColor}${GIT_PROMPT_SUFFIX}" - NEW_PROMPT="$(gp_add_virtualenv_to_prompt)${PROMPT_START}$(${prompt_callback})${STATUS_PREFIX}${STATUS}${PROMPT_END}" + if [[ "${GIT_PROMPT_VIRTUAL_ENV_AFTER_PROMPT:-0}" == "0" ]]; then + NEW_PROMPT="$(gp_add_virtualenv_to_prompt)${PROMPT_START}$(${prompt_callback})${STATUS_PREFIX}${STATUS}${PROMPT_END}" + else + NEW_PROMPT="${PROMPT_START}$(${prompt_callback})$(gp_add_virtualenv_to_prompt)${STATUS_PREFIX}${STATUS}${PROMPT_END}" + fi else NEW_PROMPT="${EMPTY_PROMPT}" fi From feb7f35732313288709e9fde7680d1bb7fb96ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Skalski?= Date: Sun, 16 Oct 2022 11:21:30 +0200 Subject: [PATCH 24/40] Honour TMPDIR variable for cases when /tmp dir does not exist (i.e. on termux) Private index was tried to create in nonexistent location, no error was ever displayed, and then unconditionally GIT_INDEX_FILE variable was set pointing to nonexistent path. Git used this location and reported many changed files. It is common on Android devices - there is no /tmp directory Termux creates one and sets TMPDIR variable, which is commonly honored by most of unix utilities. Fixes issue #338 - Fixes behaviour if `/tmp` dir does not exist --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index f8ecd68b..09f50a8d 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -472,7 +472,7 @@ function createPrivateIndex { else __GIT_INDEX_FILE="${GIT_INDEX_FILE}" fi - __GIT_INDEX_PRIVATE="/tmp/git-index-private$$" + __GIT_INDEX_PRIVATE="${TMPDIR:-/tmp}/git-index-private$$" command cp "${__GIT_INDEX_FILE}" "${__GIT_INDEX_PRIVATE}" 2>/dev/null echo "${__GIT_INDEX_PRIVATE}" } From 6dbba2429e97a9f8f1815b5f3978183f51c59e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Skalski?= Date: Sun, 16 Oct 2022 11:29:12 +0200 Subject: [PATCH 25/40] Fixes git state 'D' was wrongly identified as 'stashed'. Additionally in case of nonexistent index file (i.e. when `/tmp` does not exist) most of files were marked with 'D' in second loop pass of `gitstatus.sh` which was wrongly identified as 'Stashed'. Now it is idenified as 'changed' --- gitstatus.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/gitstatus.sh b/gitstatus.sh index 76ffb43c..e8f921dc 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -105,7 +105,6 @@ while IFS='' read -r line || [[ -n "${line}" ]]; do AA) ((num_conflicts++)); break;; #two character matches, first loop ?M) ((num_changed++)) ;; - ?D) ((num_changed++)) ;; ?\ ) ;; #single character matches, second loop U) ((num_conflicts++)) ;; From 0101261948e2e3b946484990e95a9f8700ace156 Mon Sep 17 00:00:00 2001 From: Vitaly Zdanevich Date: Mon, 24 Oct 2022 18:21:17 +0300 Subject: [PATCH 26/40] README: add block with similar projects --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 28d7ac2b..5f988e45 100644 --- a/README.md +++ b/README.md @@ -352,6 +352,9 @@ Please leave a comment on the issue, that you want to fix it, so others know, th Pull requests are welcome. I will check them and merge them, if I think they help the project. +## Similar projects +https://github.com/ohmybash/oh-my-bash + ## Donations I accept tips through [Flattr][flattr]. From a9fd3911ce56fb49edf42eb9c09751ba5d8e5204 Mon Sep 17 00:00:00 2001 From: Norbert Ronecker Date: Fri, 14 Oct 2022 09:59:12 +0200 Subject: [PATCH 27/40] Multi Line Theme for Gentoo Default Prompt without Exit State The longer the directory structure, the more convenient and useful is a new-line. --- themes/Multi_line_NoExitState_Gentoo.bgptheme | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 themes/Multi_line_NoExitState_Gentoo.bgptheme diff --git a/themes/Multi_line_NoExitState_Gentoo.bgptheme b/themes/Multi_line_NoExitState_Gentoo.bgptheme new file mode 100644 index 00000000..58aa7d40 --- /dev/null +++ b/themes/Multi_line_NoExitState_Gentoo.bgptheme @@ -0,0 +1,20 @@ +# This is a theme for gitprompt.sh, +# it uses the default Gentoo bash prompt style. + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Multi_line_NoExitState_Gentoo" + GIT_PROMPT_BRANCH="${Cyan}" + GIT_PROMPT_MASTER_BRANCH="${GIT_PROMPT_BRANCH}" + GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}" + GIT_PROMPT_CHANGED="${Yellow}✚ " + GIT_PROMPT_STAGED="${Magenta}●" + + GIT_PROMPT_START_USER="${BoldGreen}\u@\h ${BrightBlue}\w${ResetColor}\n" + GIT_PROMPT_START_ROOT="${BoldRed}\h ${BrightBlue}\w${ResetColor}\n" + + GIT_PROMPT_END_USER="${BrightBlue} \$ ${ResetColor}" + GIT_PROMPT_END_ROOT="${BrightBlue} \$ ${ResetColor}" +} + +reload_git_prompt_colors "Multi_line_NoExitState_Gentoo" + From cd2326dfedc6028c8ef94996542518569d4ffebd Mon Sep 17 00:00:00 2001 From: Norbert Szivos Date: Sat, 29 Feb 2020 12:10:03 +0100 Subject: [PATCH 28/40] Add new theme BlackOrWhite --- themes/BlackOrWhite.bgptheme | 129 +++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 themes/BlackOrWhite.bgptheme diff --git a/themes/BlackOrWhite.bgptheme b/themes/BlackOrWhite.bgptheme new file mode 100644 index 00000000..75170440 --- /dev/null +++ b/themes/BlackOrWhite.bgptheme @@ -0,0 +1,129 @@ +###################################################################################### +# This theme for gitprompt.sh is created for the dark and light color schemes as well. +# Base colors of the theme can be black or white, it depends on which color needed. +# The user, hostname, time and current path text are using the terminal text color. +# Git branch state part is using similar colors like git (red, green). +# Also configurable to display user@hostname/time, last command state and an icon +# before the branch name. +# Powerline fonts are needed to display branch icon. +# +# By default the prompt base color is black. You can use white color with +# GIT_PROMPT_BLACK_OR_WHITE_THEME_PS1_COLOR=white +# +# By default the prompt display the user and hostname, but you can choose to +# display time instead with +# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_TIME_INSTEAD_OF_USER=1 +# +# By default the last command state is disabled. You can switch on with +# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_LAST_COMMAND_STATE=1 +# +# By default to display the branch icon is disabled. You can switch on with +# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_BRANCH_ICON=1 +# +# Example usage: +# if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then +# GIT_PROMPT_THEME=BlackOrWhite +# GIT_PROMPT_BLACK_OR_WHITE_THEME_PS1_COLOR=white +# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_TIME_INSTEAD_OF_USER=1 +# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_LAST_COMMAND_STATE=1 +# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_BRANCH_ICON=1 +# source $HOME/.bash-git-prompt/gitprompt.sh +# fi +# +# Samples: +# +# Display user and hostname +# ┌─(user@hostname)──(~) +# └─• +# +# Display time instead of user and hostname +# ┌─(10:58:58)──(~) +# └─• +# +# Display root user prompt +# ┌─(11:08:06)──(/home/root) +# └─! +# +# Display git branch without or with the branch icon +# ┌─(10:59:31)──(~/.bash-git-prompt)──(master|✔) +# └─• +# +# ┌─(10:59:31)──(~/.bash-git-prompt)──( master|✔) +# └─• +# +# Display git branch with upstream +# ┌─(user@hostname)──(~/.bash-git-prompt)──( master {origin/master}|…1) +# └─• +# +# Display last command state +# ┌─(user@hostname)──(~/.bash-git-prompt)──(>_ ✔)──( master|…1) +# └─• +# +###################################################################################### +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="BlackOrWhite" + + local PathShort="\w" + local PS1Color="${BoldBlack}" + + case $GIT_PROMPT_BLACK_OR_WHITE_THEME_PS1_COLOR in + black) + PS1Color="${BoldBlack}" + ;; + white) + PS1Color="${BoldWhite}" + ;; + esac + + local FirstBubbleContent="\u${PS1Color}@${ResetColor}\h" + local CommandStateBubbleContent="" + local BranchIcon="" + + if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_TIME_INSTEAD_OF_USER}" == "1" ]]; then + FirstBubbleContent="\t" + fi + + if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_LAST_COMMAND_STATE}" == "1" ]]; then + CommandStateBubbleContent=")──(${ResetColor}>_ _LAST_COMMAND_INDICATOR_${PS1Color}" + fi + + if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_BRANCH_ICON}" == "1" ]]; then + BranchIcon=" " + fi + + GIT_PROMPT_LEADING_SPACE=0 + + GIT_PROMPT_PREFIX="${PS1Color}──(${ResetColor}${BranchIcon}" + GIT_PROMPT_SUFFIX="${PS1Color})${ResetColor}" + # GIT_PROMPT_SEPARATOR="|" + + GIT_PROMPT_BRANCH="${PS1Color}" + GIT_PROMPT_MASTER_BRANCH="${GIT_PROMPT_BRANCH}" + GIT_PROMPT_STAGED="${BoldGreen}•" + GIT_PROMPT_CONFLICTS="${BoldRed}x" + GIT_PROMPT_CHANGED="${BoldRed}+" + + # GIT_PROMPT_REMOTE=" " + GIT_PROMPT_UNTRACKED="${PS1Color}…" + GIT_PROMPT_STASHED="${PS1Color}⚑ " + GIT_PROMPT_CLEAN="${BoldGreen}✔" + + # GIT_PROMPT_COMMAND_OK="${Green}✔" + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" + + # GIT_PROMPT_SYMBOLS_AHEAD="↑·" + # GIT_PROMPT_SYMBOLS_BEHIND="↓·" + # GIT_PROMPT_SYMBOLS_PREHASH=":" + # GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L" + + GIT_PROMPT_VIRTUALENV="[${PS1Color}_VIRTUALENV_${ResetColor}] " + + GIT_PROMPT_UPSTREAM=" {${PS1Color}_UPSTREAM_${ResetColor}}" + + GIT_PROMPT_START_USER="\n${PS1Color}┌─(${ResetColor}${FirstBubbleContent}${PS1Color})──(${ResetColor}${PathShort}${PS1Color}${CommandStateBubbleContent})${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER="\n${PS1Color}└─•${ResetColor} " + GIT_PROMPT_END_ROOT="\n${PS1Color}└─!${ResetColor} " +} + +reload_git_prompt_colors "BlackOrWhite" From 31e5a41c8a4026911c02481afc6aa1be8863d4fe Mon Sep 17 00:00:00 2001 From: Norbert Szivos Date: Mon, 14 Dec 2020 12:00:35 +0100 Subject: [PATCH 29/40] Add Nerd Fonts to BlackOrWhite theme --- themes/BlackOrWhite.bgptheme | 109 ++++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 27 deletions(-) diff --git a/themes/BlackOrWhite.bgptheme b/themes/BlackOrWhite.bgptheme index 75170440..c032e960 100644 --- a/themes/BlackOrWhite.bgptheme +++ b/themes/BlackOrWhite.bgptheme @@ -3,9 +3,9 @@ # Base colors of the theme can be black or white, it depends on which color needed. # The user, hostname, time and current path text are using the terminal text color. # Git branch state part is using similar colors like git (red, green). -# Also configurable to display user@hostname/time, last command state and an icon -# before the branch name. -# Powerline fonts are needed to display branch icon. +# Also configurable to display user@hostname/time, last command state and additional +# icons before content. +# Powerline and/or Nerd fonts are needed to display icons. # # By default the prompt base color is black. You can use white color with # GIT_PROMPT_BLACK_OR_WHITE_THEME_PS1_COLOR=white @@ -17,8 +17,11 @@ # By default the last command state is disabled. You can switch on with # GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_LAST_COMMAND_STATE=1 # -# By default to display the branch icon is disabled. You can switch on with -# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_BRANCH_ICON=1 +# By default to display the powerline icon is disabled. You can switch on with +# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_POWERLINE_ICON=1 +# +# By default to display the nerd fonts icons are disabled. You can switch on with +# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_NERD_FONTS_ICONS=1 # # Example usage: # if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then @@ -26,7 +29,8 @@ # GIT_PROMPT_BLACK_OR_WHITE_THEME_PS1_COLOR=white # GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_TIME_INSTEAD_OF_USER=1 # GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_LAST_COMMAND_STATE=1 -# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_BRANCH_ICON=1 +# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_POWERLINE_ICON=1 +# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_NERD_FONTS_ICONS=1 # source $HOME/.bash-git-prompt/gitprompt.sh # fi # @@ -44,7 +48,7 @@ # ┌─(11:08:06)──(/home/root) # └─! # -# Display git branch without or with the branch icon +# Display git branch without or with the powerline icon # ┌─(10:59:31)──(~/.bash-git-prompt)──(master|✔) # └─• # @@ -59,6 +63,13 @@ # ┌─(user@hostname)──(~/.bash-git-prompt)──(>_ ✔)──( master|…1) # └─• # +# Display nerd fonts icons +# ┌─( user)──( hostname)──( ~/.bash-git-prompt)──(  )──( master| 2) +# └─• +# +# ┌─( 11:45:19)──( ~/.bash-git-prompt)──(  )──( master| 2) +# └─• +# ###################################################################################### override_git_prompt_colors() { GIT_PROMPT_THEME_NAME="BlackOrWhite" @@ -77,18 +88,62 @@ override_git_prompt_colors() { local FirstBubbleContent="\u${PS1Color}@${ResetColor}\h" local CommandStateBubbleContent="" + local PathBubbleContent="" + + local UserIcon="" + local ComputerIcon="" + local ClockIcon="" + local CommandPromptIcon=">_ " + local FolderIcon="" local BranchIcon="" + local StagedIcon="•" + local ConflictsIcon="x" + local ChangedIcon="+" + local RemoteIcon=" " + local UntrackedIcon="…" + local StashedIcon="⚑ " + local CleanIcon="✔" + local CommandOkIcon="✔" + local CommandFailIcon="✘" + local AheadIcon="↑·" + local BehindIcon="↓·" + local PrehashIcon=":" + local NoRemoteTrackingIcon="L" + + if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_NERD_FONTS_ICONS}" == "1" ]]; then + UserIcon=" " + ComputerIcon=" " + ClockIcon=" " + CommandPromptIcon=" " + FolderIcon=" " + BranchIcon=" " + StagedIcon=" " + ConflictsIcon="ﴜ " + ChangedIcon=" " + UntrackedIcon=" " + StashedIcon=" " + CleanIcon=" " + CommandOkIcon=" " + CommandFailIcon=" " + AheadIcon=" " + BehindIcon=" " + NoRemoteTrackingIcon=" " + fi - if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_TIME_INSTEAD_OF_USER}" == "1" ]]; then - FirstBubbleContent="\t" + if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_POWERLINE_ICON}" == "1" ]]; then + BranchIcon=" " fi - if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_LAST_COMMAND_STATE}" == "1" ]]; then - CommandStateBubbleContent=")──(${ResetColor}>_ _LAST_COMMAND_INDICATOR_${PS1Color}" + if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_TIME_INSTEAD_OF_USER}" == "1" ]]; then + FirstBubbleContent="${ClockIcon}\t" + elif [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_NERD_FONTS_ICONS}" == "1" ]]; then + FirstBubbleContent="${UserIcon}\u${PS1Color})──(${ResetColor}${ComputerIcon}\h" fi - if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_BRANCH_ICON}" == "1" ]]; then - BranchIcon=" " + PathBubbleContent="${FolderIcon}${PathShort}" + + if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_LAST_COMMAND_STATE}" == "1" ]]; then + CommandStateBubbleContent=")──(${ResetColor}${CommandPromptIcon}_LAST_COMMAND_INDICATOR_${PS1Color}" fi GIT_PROMPT_LEADING_SPACE=0 @@ -99,28 +154,28 @@ override_git_prompt_colors() { GIT_PROMPT_BRANCH="${PS1Color}" GIT_PROMPT_MASTER_BRANCH="${GIT_PROMPT_BRANCH}" - GIT_PROMPT_STAGED="${BoldGreen}•" - GIT_PROMPT_CONFLICTS="${BoldRed}x" - GIT_PROMPT_CHANGED="${BoldRed}+" + GIT_PROMPT_STAGED="${BoldGreen}${StagedIcon}" + GIT_PROMPT_CONFLICTS="${BoldRed}${ConflictsIcon}" + GIT_PROMPT_CHANGED="${BoldRed}${ChangedIcon}" - # GIT_PROMPT_REMOTE=" " - GIT_PROMPT_UNTRACKED="${PS1Color}…" - GIT_PROMPT_STASHED="${PS1Color}⚑ " - GIT_PROMPT_CLEAN="${BoldGreen}✔" + GIT_PROMPT_REMOTE="${RemoteIcon}" + GIT_PROMPT_UNTRACKED="${PS1Color}${UntrackedIcon}" + GIT_PROMPT_STASHED="${PS1Color}${StashedIcon}" + GIT_PROMPT_CLEAN="${BoldGreen}${CleanIcon}" - # GIT_PROMPT_COMMAND_OK="${Green}✔" - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" + GIT_PROMPT_COMMAND_OK="${Green}${CommandOkIcon}" + GIT_PROMPT_COMMAND_FAIL="${Red}${CommandFailIcon}-_LAST_COMMAND_STATE_" - # GIT_PROMPT_SYMBOLS_AHEAD="↑·" - # GIT_PROMPT_SYMBOLS_BEHIND="↓·" - # GIT_PROMPT_SYMBOLS_PREHASH=":" - # GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L" + GIT_PROMPT_SYMBOLS_AHEAD="${AheadIcon}" + GIT_PROMPT_SYMBOLS_BEHIND="${BehindIcon}" + GIT_PROMPT_SYMBOLS_PREHASH="${PrehashIcon}" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="${NoRemoteTrackingIcon}" GIT_PROMPT_VIRTUALENV="[${PS1Color}_VIRTUALENV_${ResetColor}] " GIT_PROMPT_UPSTREAM=" {${PS1Color}_UPSTREAM_${ResetColor}}" - GIT_PROMPT_START_USER="\n${PS1Color}┌─(${ResetColor}${FirstBubbleContent}${PS1Color})──(${ResetColor}${PathShort}${PS1Color}${CommandStateBubbleContent})${ResetColor}" + GIT_PROMPT_START_USER="\n${PS1Color}┌─(${ResetColor}${FirstBubbleContent}${PS1Color})──(${ResetColor}${PathBubbleContent}${PS1Color}${CommandStateBubbleContent})${ResetColor}" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" GIT_PROMPT_END_USER="\n${PS1Color}└─•${ResetColor} " GIT_PROMPT_END_ROOT="\n${PS1Color}└─!${ResetColor} " From 31c47f70572f622b05fdee60cf10fb41d0eb75bd Mon Sep 17 00:00:00 2001 From: Norbert Szivos Date: Sun, 16 Oct 2022 10:16:37 +0200 Subject: [PATCH 30/40] Improve BlackOrWhite.bgptheme * It has three styles of prompt. * It is configurable * the visible sections and the order of the sections, * where to show icons. * This theme is not using most of the old configuration variables, it has new ones. To use this new version of the theme, please read the theme documentation. --- themes/BlackOrWhite.bgptheme | 448 ++++++++++++++++++++++++++++------- 1 file changed, 362 insertions(+), 86 deletions(-) diff --git a/themes/BlackOrWhite.bgptheme b/themes/BlackOrWhite.bgptheme index c032e960..81611e5e 100644 --- a/themes/BlackOrWhite.bgptheme +++ b/themes/BlackOrWhite.bgptheme @@ -1,40 +1,87 @@ ###################################################################################### # This theme for gitprompt.sh is created for the dark and light color schemes as well. # Base colors of the theme can be black or white, it depends on which color needed. -# The user, hostname, time and current path text are using the terminal text color. +# The text is using the terminal text color. # Git branch state part is using similar colors like git (red, green). -# Also configurable to display user@hostname/time, last command state and additional -# icons before content. -# Powerline and/or Nerd fonts are needed to display icons. +# Also, configurable which part to display and where to show icons. +# Nerd fonts are needed to display icons. # -# By default the prompt base color is black. You can use white color with -# GIT_PROMPT_BLACK_OR_WHITE_THEME_PS1_COLOR=white +# Settings: +# ========= # -# By default the prompt display the user and hostname, but you can choose to -# display time instead with -# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_TIME_INSTEAD_OF_USER=1 +# Color options: +# -------------- +# Variable name: GIT_PROMPT_BLACK_OR_WHITE_THEME_PS1_COLOR +# Possible values: +# - black (default) +# - white # -# By default the last command state is disabled. You can switch on with -# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_LAST_COMMAND_STATE=1 +# Command prompt styles: +# ---------------------- +# Variable name: GIT_PROMPT_BLACK_OR_WHITE_THEME_STYLE +# Possible values: +# - bubbles (default) +# - bubbles_with_double_line +# - powerline # -# By default to display the powerline icon is disabled. You can switch on with -# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_POWERLINE_ICON=1 +# Visible sections: +# ----------------- +# This is a comma-separated list of the shown sections. It will show the sections +# as you add to the list. If this variable is missing or it has no any values, +# then it will show the path. # -# By default to display the nerd fonts icons are disabled. You can switch on with -# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_NERD_FONTS_ICONS=1 +# Variable name: GIT_PROMPT_BLACK_OR_WHITE_THEME_VISIBLE_SECTIONS +# Possible options: +# - hostname +# - last_command_state +# - os (OS name) +# - os_icon (Only the OS icon) +# - time +# - user +# - user_and_hostname +# - path (default) +# +# Icons in sections: +# ----------------- +# This is a comma-separated list of the shown icons in sections. It will show an +# icon if originally was not there or it will replace the default icon. +# +# Variable name: GIT_PROMPT_BLACK_OR_WHITE_THEME_ADD_OR_REPLACE_ICONS_IN_SECTIONS +# Possible options: +# - git_branch (add branch icon before the branch name) +# - git_branch_powerline (add the powerline branch icon before the branch name) +# - git_status (replace the original icons) +# - hostname (add icon to the hostname section) +# - last_command_state_ok_fail (replace the original icons in the last_command_state section) +# - last_command_state_prompt (replace the original icons in the last_command_state section) +# - os (add icon to the os section) +# - path (add icon to the path section) +# - time (add icon to the time section) +# - user (add icon to the user section) +# +# Extra space after icons: +# ------------------------ +# Sometimes you need extra space after icons (because of the size of the icons). +# +# Variable name: GIT_PROMPT_BLACK_OR_WHITE_THEME_ADD_EXTRA_SPACE_AFTER_ICONS +# Possible options: +# - true +# - false # # Example usage: +# -------------- # if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then # GIT_PROMPT_THEME=BlackOrWhite # GIT_PROMPT_BLACK_OR_WHITE_THEME_PS1_COLOR=white -# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_TIME_INSTEAD_OF_USER=1 -# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_LAST_COMMAND_STATE=1 -# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_POWERLINE_ICON=1 -# GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_NERD_FONTS_ICONS=1 +# GIT_PROMPT_BLACK_OR_WHITE_THEME_STYLE=bubbles +# GIT_PROMPT_BLACK_OR_WHITE_THEME_VISIBLE_SECTIONS=os_icon,path,last_command_state +# GIT_PROMPT_BLACK_OR_WHITE_THEME_ADD_OR_REPLACE_ICONS_IN_SECTIONS=path,last_command_state_prompt,last_command_state_ok_fail,git_branch_powerline,git_status +# GIT_PROMPT_BLACK_OR_WHITE_THEME_ADD_EXTRA_SPACE_AFTER_ICONS=true # source $HOME/.bash-git-prompt/gitprompt.sh # fi # # Samples: +# ======== # # Display user and hostname # ┌─(user@hostname)──(~) @@ -46,13 +93,13 @@ # # Display root user prompt # ┌─(11:08:06)──(/home/root) -# └─! +# └─(!)─• # -# Display git branch without or with the powerline icon -# ┌─(10:59:31)──(~/.bash-git-prompt)──(master|✔) +# Display git branch with or without the branch icon +# ┌─(10:59:31)──(~/.bash-git-prompt)──( master|✔) # └─• # -# ┌─(10:59:31)──(~/.bash-git-prompt)──( master|✔) +# ┌─(10:59:31)──(~/.bash-git-prompt)──(master|✔) # └─• # # Display git branch with upstream @@ -63,122 +110,351 @@ # ┌─(user@hostname)──(~/.bash-git-prompt)──(>_ ✔)──( master|…1) # └─• # -# Display nerd fonts icons -# ┌─( user)──( hostname)──( ~/.bash-git-prompt)──(  )──( master| 2) +# Display sections with icons +# ┌─( user)──( hostname)──( ~/.bash-git-prompt)──(  )──( master| 2) +# └─• +# +# ┌─( 11:45:19)──( ~/.bash-git-prompt)──(  )──( master| 2) +# └─• +# +# Display prompt in different styles +# ╔═( macos)══( user)══( hostname)══( ~)══(  ) +# ╚═> +# +# ╔═( macos)══( user)══( hostname)══( ~/.bash-git-prompt)══(  ) +# ╠═( master  | 1) +# ╚═> +# +# ┌─    user   hostname   ~    # └─• # -# ┌─( 11:45:19)──( ~/.bash-git-prompt)──(  )──( master| 2) +# ┌─    user   hostname   ~/.bash-git-prompt      master  | 1 # └─• # ###################################################################################### override_git_prompt_colors() { GIT_PROMPT_THEME_NAME="BlackOrWhite" - local PathShort="\w" - local PS1Color="${BoldBlack}" + local ResetColor="\[\033[0m\]" + local PS1BoldBlackColor="\[\033[1;30m\]" # Bold black no background + local PS1BoldWhiteColor="\[\033[1;97m\]" # Bold white no background + local PS1BoldGreenColor="\[\033[1;32m\]" # Bold green no background + local PS1BoldRedColor="\[\033[1;31m\]" # Bold red no background + local PS1WhiteBlackBackgroundColor="\[\033[0;97;40m\]" # White with black background + local PS1GreenBlackBackgroundColor="\[\033[0;32;40m\]" # Green with black background + local PS1RedBlackBackgroundColor="\[\033[0;31;40m\]" # Red with black background + local PS1BlackWhiteBackgroundColor="\[\033[0;30;107m\]" # Black with white background + local PS1GreenWhiteBackgroundColor="\[\033[0;32;107m\]" # Green with white background + local PS1RedWhiteBackgroundColor="\[\033[0;31;107m\]" # Red with white background + + local PS1Color="${PS1BoldBlackColor}" + local PS1GreenColor="${PS1BoldGreenColor}" + local PS1RedColor="${PS1BoldRedColor}" + local PS1SartEndColor="${PS1BoldBlackColor}" + local PS1ResetColor="${ResetColor}" case $GIT_PROMPT_BLACK_OR_WHITE_THEME_PS1_COLOR in - black) - PS1Color="${BoldBlack}" + black ) + # Default ;; - white) - PS1Color="${BoldWhite}" + + white ) + PS1Color="${PS1BoldWhiteColor}" + PS1SartEndColor="${PS1BoldWhiteColor}" ;; esac - local FirstBubbleContent="\u${PS1Color}@${ResetColor}\h" - local CommandStateBubbleContent="" - local PathBubbleContent="" + local PromptStartPrefix="┌─(" + local PromptStartMiddle=")──(" + local PromptStartSuffix=")" + local PromptGitPrefix="──(" + local PromptGitSuffix=")" + local PromptEndUser="└─•" + local PromptEndRoot="└─(!)─•" + + case $GIT_PROMPT_BLACK_OR_WHITE_THEME_STYLE in + bubbles ) + # Default + ;; + bubbles_with_double_line ) + PromptStartPrefix="╔═(" + PromptStartMiddle=")══(" + PromptStartSuffix=")" + PromptGitPrefix="\n╠═(" + PromptGitSuffix=")" + PromptEndUser="╚═>" + PromptEndRoot="╚═(!)═>" + ;; + + powerline ) + PS1ResetColor="" + + case $GIT_PROMPT_BLACK_OR_WHITE_THEME_PS1_COLOR in + black ) + PS1Color="${PS1WhiteBlackBackgroundColor}" + PS1GreenColor="${PS1GreenBlackBackgroundColor}" + PS1RedColor="${PS1RedBlackBackgroundColor}" + ;; + + white ) + PS1Color="${PS1BlackWhiteBackgroundColor}" + PS1GreenColor="${PS1GreenWhiteBackgroundColor}" + PS1RedColor="${PS1RedWhiteBackgroundColor}" + ;; + esac + + PromptStartPrefix="┌─${ResetColor}${PS1Color} " + PromptStartMiddle="  " + PromptStartSuffix="" + PromptGitPrefix=" " + PromptGitSuffix=" " + ;; + esac + + local OsType="" + + case "$(uname)" in + Darwin ) + OsType="macos" + ;; + + Linux ) + OsType="$(cat /etc/os-release | grep ^ID= | cut -d'=' -f2)" + ;; + esac + + local ExtraSpaceAfterIcon="" + + if [[ "$GIT_PROMPT_BLACK_OR_WHITE_THEME_ADD_EXTRA_SPACE_AFTER_ICONS" == "true" ]]; then + ExtraSpaceAfterIcon=" " + fi + + # os + local OsIcon="" + # user local UserIcon="" + # hostname local ComputerIcon="" + # time local ClockIcon="" - local CommandPromptIcon=">_ " + # path local FolderIcon="" + # last_command_state + local CommandPromptIcon=">_ " + local CommandOkIcon="✔" + local CommandFailIcon="✘" + # git local BranchIcon="" local StagedIcon="•" local ConflictsIcon="x" local ChangedIcon="+" local RemoteIcon=" " local UntrackedIcon="…" - local StashedIcon="⚑ " + local StashedIcon="⚑${ExtraSpaceAfterIcon}" local CleanIcon="✔" - local CommandOkIcon="✔" - local CommandFailIcon="✘" local AheadIcon="↑·" local BehindIcon="↓·" local PrehashIcon=":" local NoRemoteTrackingIcon="L" - if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_NERD_FONTS_ICONS}" == "1" ]]; then - UserIcon=" " - ComputerIcon=" " - ClockIcon=" " - CommandPromptIcon=" " - FolderIcon=" " - BranchIcon=" " - StagedIcon=" " - ConflictsIcon="ﴜ " - ChangedIcon=" " - UntrackedIcon=" " - StashedIcon=" " - CleanIcon=" " - CommandOkIcon=" " - CommandFailIcon=" " - AheadIcon=" " - BehindIcon=" " - NoRemoteTrackingIcon=" " - fi + for IconInSection in ${GIT_PROMPT_BLACK_OR_WHITE_THEME_ADD_OR_REPLACE_ICONS_IN_SECTIONS//,/ }; do + case $IconInSection in + os ) + case $OsType in + macos ) + OsIcon=" ${ExtraSpaceAfterIcon}" + ;; - if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_POWERLINE_ICON}" == "1" ]]; then - BranchIcon=" " - fi + archlinux ) + OsIcon=" ${ExtraSpaceAfterIcon}" + ;; + + centos ) + OsIcon=" ${ExtraSpaceAfterIcon}" + ;; + + debian ) + OsIcon=" ${ExtraSpaceAfterIcon}" + ;; + + fedora ) + OsIcon=" ${ExtraSpaceAfterIcon}" + ;; + + gentoo ) + OsIcon=" ${ExtraSpaceAfterIcon}" + ;; + + linuxmint ) + OsIcon=" ${ExtraSpaceAfterIcon}" + ;; + + opensuse ) + OsIcon=" ${ExtraSpaceAfterIcon}" + ;; + + redhat ) + OsIcon=" ${ExtraSpaceAfterIcon}" + ;; + + ubuntu ) + OsIcon=" ${ExtraSpaceAfterIcon}" + ;; + esac + ;; + + user ) + UserIcon=" ${ExtraSpaceAfterIcon}" + ;; + + hostname ) + ComputerIcon=" ${ExtraSpaceAfterIcon}" + ;; + + time ) + ClockIcon=" ${ExtraSpaceAfterIcon}" + ;; + + path ) + FolderIcon=" ${ExtraSpaceAfterIcon}" + ;; + + last_command_state_prompt ) + CommandPromptIcon=" ${ExtraSpaceAfterIcon}" + ;; + + last_command_state_ok_fail ) + CommandOkIcon="${ExtraSpaceAfterIcon}" + CommandFailIcon="${ExtraSpaceAfterIcon}" + ;; + + git_branch_powerline ) + BranchIcon=" " + ;; + + git_branch ) + BranchIcon=" " + ;; + + git_status ) + StagedIcon="${ExtraSpaceAfterIcon}" + ConflictsIcon="ﴜ${ExtraSpaceAfterIcon}" + ChangedIcon="${ExtraSpaceAfterIcon}" + UntrackedIcon="${ExtraSpaceAfterIcon}" + StashedIcon="${ExtraSpaceAfterIcon}" + CleanIcon="${ExtraSpaceAfterIcon}" + AheadIcon="${ExtraSpaceAfterIcon}${ExtraSpaceAfterIcon}" + BehindIcon="${ExtraSpaceAfterIcon}${ExtraSpaceAfterIcon}" + NoRemoteTrackingIcon="${ExtraSpaceAfterIcon}" + ;; + esac + done + + local SectionAdded=0 + local SectionAddedCounter=0 + + GIT_PROMPT_START_USER="\n${PS1SartEndColor}${PromptStartPrefix}${PS1ResetColor}" + + for VisibleSection in ${GIT_PROMPT_BLACK_OR_WHITE_THEME_VISIBLE_SECTIONS//,/ }; do + if [[ $SectionAdded -eq 1 ]]; then + GIT_PROMPT_START_USER+="${PS1Color}${PromptStartMiddle}${PS1ResetColor}" + SectionAdded=0 + fi + + case $VisibleSection in + os ) + GIT_PROMPT_START_USER+="${OsIcon}${OsType}" + SectionAdded=1 + ((SectionAddedCounter++)) + ;; + + os_icon ) + GIT_PROMPT_START_USER+="${OsIcon%?}" + SectionAdded=1 + ((SectionAddedCounter++)) + ;; + + user ) + GIT_PROMPT_START_USER+="${UserIcon}\u" + SectionAdded=1 + ((SectionAddedCounter++)) + ;; + + hostname ) + GIT_PROMPT_START_USER+="${ComputerIcon}\h" + SectionAdded=1 + ((SectionAddedCounter++)) + ;; + + user_and_hostname ) + GIT_PROMPT_START_USER+="\u${PS1Color}@${PS1ResetColor}\h" + SectionAdded=1 + ((SectionAddedCounter++)) + ;; + + time ) + GIT_PROMPT_START_USER+="${ClockIcon}\t" + SectionAdded=1 + ((SectionAddedCounter++)) + ;; + + path ) + GIT_PROMPT_START_USER+="${FolderIcon}\w" + SectionAdded=1 + ((SectionAddedCounter++)) + ;; + + last_command_state ) + GIT_PROMPT_START_USER+="${CommandPromptIcon}_LAST_COMMAND_INDICATOR_" + SectionAdded=1 + ((SectionAddedCounter++)) + ;; + esac + done - if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_TIME_INSTEAD_OF_USER}" == "1" ]]; then - FirstBubbleContent="${ClockIcon}\t" - elif [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_NERD_FONTS_ICONS}" == "1" ]]; then - FirstBubbleContent="${UserIcon}\u${PS1Color})──(${ResetColor}${ComputerIcon}\h" + if [[ $SectionAddedCounter -eq 0 ]]; then + GIT_PROMPT_START_USER+="\w" fi - PathBubbleContent="${FolderIcon}${PathShort}" + GIT_PROMPT_START_USER+="${PS1Color}${PromptStartSuffix}${PS1ResetColor}" - if [[ "${GIT_PROMPT_BLACK_OR_WHITE_THEME_SHOW_LAST_COMMAND_STATE}" == "1" ]]; then - CommandStateBubbleContent=")──(${ResetColor}${CommandPromptIcon}_LAST_COMMAND_INDICATOR_${PS1Color}" + if [[ "$GIT_PROMPT_BLACK_OR_WHITE_THEME_STYLE" == "powerline" ]]; then + GIT_PROMPT_START_USER+=" " fi GIT_PROMPT_LEADING_SPACE=0 - GIT_PROMPT_PREFIX="${PS1Color}──(${ResetColor}${BranchIcon}" - GIT_PROMPT_SUFFIX="${PS1Color})${ResetColor}" - # GIT_PROMPT_SEPARATOR="|" + GIT_PROMPT_PREFIX="${PS1Color}${PromptGitPrefix}${PS1ResetColor}${BranchIcon}" + GIT_PROMPT_SUFFIX="${PS1Color}${PromptGitSuffix}${PS1ResetColor}" + GIT_PROMPT_SEPARATOR="${PS1Color}${PS1ResetColor}|" GIT_PROMPT_BRANCH="${PS1Color}" GIT_PROMPT_MASTER_BRANCH="${GIT_PROMPT_BRANCH}" - GIT_PROMPT_STAGED="${BoldGreen}${StagedIcon}" - GIT_PROMPT_CONFLICTS="${BoldRed}${ConflictsIcon}" - GIT_PROMPT_CHANGED="${BoldRed}${ChangedIcon}" + GIT_PROMPT_STAGED="${PS1GreenColor}${StagedIcon}" + GIT_PROMPT_CONFLICTS="${PS1RedColor}${ConflictsIcon}" + GIT_PROMPT_CHANGED="${PS1RedColor}${ChangedIcon}" - GIT_PROMPT_REMOTE="${RemoteIcon}" + GIT_PROMPT_REMOTE="${PS1Color}${RemoteIcon}" GIT_PROMPT_UNTRACKED="${PS1Color}${UntrackedIcon}" GIT_PROMPT_STASHED="${PS1Color}${StashedIcon}" - GIT_PROMPT_CLEAN="${BoldGreen}${CleanIcon}" + GIT_PROMPT_CLEAN="${PS1GreenColor}${CleanIcon}" - GIT_PROMPT_COMMAND_OK="${Green}${CommandOkIcon}" - GIT_PROMPT_COMMAND_FAIL="${Red}${CommandFailIcon}-_LAST_COMMAND_STATE_" + GIT_PROMPT_COMMAND_OK="${PS1GreenColor}${CommandOkIcon}" + GIT_PROMPT_COMMAND_FAIL="${PS1RedColor}${CommandFailIcon}-_LAST_COMMAND_STATE_" - GIT_PROMPT_SYMBOLS_AHEAD="${AheadIcon}" - GIT_PROMPT_SYMBOLS_BEHIND="${BehindIcon}" + GIT_PROMPT_SYMBOLS_AHEAD="${PS1Color}${AheadIcon}" + GIT_PROMPT_SYMBOLS_BEHIND="${PS1Color}${BehindIcon}" GIT_PROMPT_SYMBOLS_PREHASH="${PrehashIcon}" - GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="${NoRemoteTrackingIcon}" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="${PS1Color}${NoRemoteTrackingIcon}" - GIT_PROMPT_VIRTUALENV="[${PS1Color}_VIRTUALENV_${ResetColor}] " + GIT_PROMPT_VIRTUALENV="${PS1Color}${PS1ResetColor}[${PS1Color}_VIRTUALENV_${PS1ResetColor}] " - GIT_PROMPT_UPSTREAM=" {${PS1Color}_UPSTREAM_${ResetColor}}" + GIT_PROMPT_UPSTREAM="${PS1Color} ${PS1ResetColor}{${PS1Color}_UPSTREAM_${PS1ResetColor}}" - GIT_PROMPT_START_USER="\n${PS1Color}┌─(${ResetColor}${FirstBubbleContent}${PS1Color})──(${ResetColor}${PathBubbleContent}${PS1Color}${CommandStateBubbleContent})${ResetColor}" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER="\n${PS1Color}└─•${ResetColor} " - GIT_PROMPT_END_ROOT="\n${PS1Color}└─!${ResetColor} " + GIT_PROMPT_END_USER="${ResetColor}${PS1SartEndColor}\n${PromptEndUser}${ResetColor} " + GIT_PROMPT_END_ROOT="${ResetColor}${PS1SartEndColor}\n${PromptEndRoot}${ResetColor} " } reload_git_prompt_colors "BlackOrWhite" From b2deaa5a959cb22a8ca137acc3c1915381397642 Mon Sep 17 00:00:00 2001 From: Juan Enciso Date: Sun, 4 Sep 2022 18:09:53 +0100 Subject: [PATCH 31/40] Add custom themes --- ...ngle_line_Minimalist_robbyrussell.bgptheme | 34 ++++++++++++++++++ ..._Minimalist_robbyrussell_kube-ps1.bgptheme | 35 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 themes/Single_line_Minimalist_robbyrussell.bgptheme create mode 100644 themes/Single_line_Minimalist_robbyrussell_kube-ps1.bgptheme diff --git a/themes/Single_line_Minimalist_robbyrussell.bgptheme b/themes/Single_line_Minimalist_robbyrussell.bgptheme new file mode 100644 index 00000000..0eec44ee --- /dev/null +++ b/themes/Single_line_Minimalist_robbyrussell.bgptheme @@ -0,0 +1,34 @@ +# This is an alternative approach. Single line minimalist in git repo. +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line_Minimalist_robbyrussell" + + function prompt_callback { + local PS1="$(gp_truncate_pwd)" + gp_set_window_title "$PS1" + } + + Time12a="\$(date +%H:%M:%S)" + Host="\h" + PathShort="\W"; + + GIT_PROMPT_PREFIX="[" + GIT_PROMPT_SUFFIX="]" + GIT_PROMPT_SEPARATOR="|" + GIT_PROMPT_STAGED="${Red}●${ResetColor}" + GIT_PROMPT_CONFLICTS="${Red}✖${ResetColor}" + GIT_PROMPT_CHANGED="${Blue}✚${ResetColor}" + GIT_PROMPT_UNTRACKED="${Cyan}…${ResetColor}" + GIT_PROMPT_STASHED="${BoldBlue}⚑${ResetColor}" + GIT_PROMPT_CLEAN="${BoldGreen}✔${ResetColor}" + + GIT_PROMPT_COMMAND_OK="${BoldGreen}➜" + GIT_PROMPT_COMMAND_FAIL="${BoldRed}➜" + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${ResetColor}${BoldCyan}${PathShort}${ResetColor}" + GIT_PROMPT_END_USER="${ResetColor} " + GIT_PROMPT_END_ROOT="${ResetColor} # " + +} + +reload_git_prompt_colors "Single_line_Minimalist_robbyrussell" + diff --git a/themes/Single_line_Minimalist_robbyrussell_kube-ps1.bgptheme b/themes/Single_line_Minimalist_robbyrussell_kube-ps1.bgptheme new file mode 100644 index 00000000..27d8ccab --- /dev/null +++ b/themes/Single_line_Minimalist_robbyrussell_kube-ps1.bgptheme @@ -0,0 +1,35 @@ +# This is an alternative approach. Single line minimalist in git repo. +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line_Minimalist_robbyrussell_kube-ps1" + + function prompt_callback { + local PS1="$(gp_truncate_pwd)" + gp_set_window_title "$PS1" + } + + Time12a="\$(date +%H:%M:%S)" + Host="\h" + PathShort="\W"; + kube_shell="\$(kube_ps1)" + + GIT_PROMPT_PREFIX="[" + GIT_PROMPT_SUFFIX="]" + GIT_PROMPT_SEPARATOR="|" + GIT_PROMPT_STAGED="${Red}●${ResetColor}" + GIT_PROMPT_CONFLICTS="${Red}✖${ResetColor}" + GIT_PROMPT_CHANGED="${Blue}✚${ResetColor}" + GIT_PROMPT_UNTRACKED="${Cyan}…${ResetColor}" + GIT_PROMPT_STASHED="${BoldBlue}⚑${ResetColor}" + GIT_PROMPT_CLEAN="${BoldGreen}✔${ResetColor}" + + GIT_PROMPT_COMMAND_OK="${BoldGreen}➜" + GIT_PROMPT_COMMAND_FAIL="${BoldRed}➜" + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${ResetColor}${BoldCyan}${PathShort}${ResetColor}${kube_shell}" + GIT_PROMPT_END_USER="${ResetColor} " + GIT_PROMPT_END_ROOT="${ResetColor} # " + +} + +reload_git_prompt_colors "Single_line_Minimalist_robbyrussell_kube-ps1" + From c9d01811b29d8acb7985e750c724cf1548d79e54 Mon Sep 17 00:00:00 2001 From: Chris Bain Date: Mon, 22 Jan 2018 22:33:26 -0500 Subject: [PATCH 32/40] Add GIT_PROMPT_SYMBOLS_PRETAG --- gitprompt.sh | 3 ++- gitstatus.sh | 2 +- themes/Default.bgptheme | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 09f50a8d..3bbe2772 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -456,8 +456,9 @@ 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}}" + local VALUE3="${VALUE2//_PRETAG_/${GIT_PROMPT_SYMBOLS_PRETAG}}" - echo "${VALUE2//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}}" + echo "${VALUE3//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}}" # reenable globbing symbols set +f diff --git a/gitstatus.sh b/gitstatus.sh index e8f921dc..ca1e3a7c 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -148,7 +148,7 @@ elif [[ "${branch}" == *"No commits yet on"* ]]; then elif [[ "${branch}" == *"no branch"* ]]; then tag=$( git describe --tags --exact-match ) if [[ -n "${tag}" ]]; then - branch="${tag}" + branch="_PRETAG_${tag}" else branch="_PREHASH_$( git rev-parse --short HEAD )" fi diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index 694ca4fa..27887a26 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -25,6 +25,7 @@ unset_git_prompt_colors() { unset GIT_PROMPT_SYMBOLS_AHEAD unset GIT_PROMPT_SYMBOLS_BEHIND unset GIT_PROMPT_SYMBOLS_PREHASH + unset GIT_PROMPT_SYMBOLS_PRETAG unset GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING } @@ -88,6 +89,7 @@ define_undefined_git_prompt_colors() { if [ -z ${GIT_PROMPT_SYMBOLS_AHEAD+x} ]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" if [ -z ${GIT_PROMPT_SYMBOLS_BEHIND+x} ]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" if [ -z ${GIT_PROMPT_SYMBOLS_PREHASH+x} ]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [ -z ${GIT_PROMPT_SYMBOLS_PRETAG+x} ]; then GIT_PROMPT_SYMBOLS_PRETAG=""; fi # Written before tag name if [ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING+x} ]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked # branch name(s) that will use $GIT_PROMPT_MASTER_BRANCH color From cada5cbbdac6741e65141efb870950abaa7d6688 Mon Sep 17 00:00:00 2001 From: Chris Bain Date: Mon, 22 Jan 2018 23:21:57 -0500 Subject: [PATCH 33/40] Add GIT_PROMPT_DETACHED_HEAD --- gitprompt.sh | 34 +++++++++++++++++++++++++--------- gitstatus.sh | 9 +++++++-- themes/Default.bgptheme | 2 ++ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 3bbe2772..06d08e1b 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -478,6 +478,28 @@ function createPrivateIndex { echo "${__GIT_INDEX_PRIVATE}" } +function get_branch_prefix() { + local GIT_BRANCH="${1}" + local DETACHED_HEAD="${2}" + + case "$GIT_BRANCH" in + ${GIT_PROMPT_MASTER_BRANCHES}) + local IS_MASTER_BRANCH=1 + ;; + *) + local IS_MASTER_BRANCH=0 + ;; + esac + + if [[ "$IS_MASTER_BRANCH" == "1" ]]; then + echo "$GIT_PROMPT_MASTER_BRANCH" + elif [[ "$DETACHED_HEAD" = "1" ]]; then + echo "$GIT_PROMPT_DETACHED_HEAD" + else + echo "$GIT_PROMPT_BRANCH" + fi +} + function updatePrompt() { local LAST_COMMAND_INDICATOR local PROMPT_LEADING_SPACE @@ -530,7 +552,7 @@ function updatePrompt() { local GIT_UNTRACKED="${git_status_fields[7]}" local GIT_STASHED="${git_status_fields[8]}" local GIT_CLEAN="${git_status_fields[9]}" - + local GIT_DETACHED_HEAD="${git_status_fields[10]}" local NEW_PROMPT="${EMPTY_PROMPT}" if [[ "${#git_status_fields[@]}" -gt 0 ]]; then @@ -545,14 +567,8 @@ function updatePrompt() { fi fi - case "${GIT_BRANCH-}" in - ${GIT_PROMPT_MASTER_BRANCHES}) - local STATUS_PREFIX="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX_FINAL}${GIT_PROMPT_MASTER_BRANCH}${URL_SHORT-}\${GIT_BRANCH}${ResetColor}${GIT_FORMATTED_UPSTREAM-}" - ;; - *) - local STATUS_PREFIX="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX_FINAL}${GIT_PROMPT_BRANCH}${URL_SHORT-}\${GIT_BRANCH}${ResetColor}${GIT_FORMATTED_UPSTREAM-}" - ;; - esac + local BRANCH_PREFIX="$(get_branch_prefix $GIT_BRANCH $GIT_DETACHED_HEAD)" + local STATUS_PREFIX="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX_FINAL}${BRANCH_PREFIX}\${GIT_BRANCH}${ResetColor}${GIT_FORMATTED_UPSTREAM}" local STATUS="" # __add_status KIND VALEXPR INSERT diff --git a/gitstatus.sh b/gitstatus.sh index ca1e3a7c..d35e3f43 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -135,6 +135,8 @@ branch="${branch_fields[0]}" remote="" upstream="" +detached_head=0 + if [[ "${branch}" == *"Initial commit on"* ]]; then IFS=" " read -ra fields <<< "${branch}" branch="${fields[3]}" @@ -149,8 +151,10 @@ elif [[ "${branch}" == *"no branch"* ]]; then tag=$( git describe --tags --exact-match ) if [[ -n "${tag}" ]]; then branch="_PRETAG_${tag}" + detached_head=1 else branch="_PREHASH_$( git rev-parse --short HEAD )" + detached_head=1 fi else if [[ "${#branch_fields[@]}" -eq 1 ]]; then @@ -183,7 +187,7 @@ fi UPSTREAM_TRIMMED=`echo $upstream |xargs` -printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ +printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ "${branch}${state}" \ "${remote}" \ "${remote_url}" \ @@ -193,6 +197,7 @@ printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ "${num_changed}" \ "${num_untracked}" \ "${num_stashed}" \ - "${clean}" + "${clean}" \ + "${detached_head}" exit diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index 27887a26..c7b1f22d 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -7,6 +7,7 @@ unset_git_prompt_colors() { unset GIT_PROMPT_SUFFIX unset GIT_PROMPT_SEPARATOR unset GIT_PROMPT_BRANCH + unset GIT_PROMPT_DETACHED_HEAD unset GIT_PROMPT_STAGED unset GIT_PROMPT_CONFLICTS unset GIT_PROMPT_CHANGED @@ -44,6 +45,7 @@ define_undefined_git_prompt_colors() { if [ -z "${GIT_PROMPT_BRANCH+x}" ]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory if [ -z "${GIT_PROMPT_MASTER_BRANCH+x}" ]; then GIT_PROMPT_MASTER_BRANCH="${GIT_PROMPT_BRANCH}"; fi # used if the git branch that is active in the current directory is $GIT_PROMPT_MASTER_BRANCHES + if [ -z "${GIT_PROMPT_DETACHED_HEAD+x}" ]; then GIT_PROMPT_DETACHED_HEAD="${GIT_PROMPT_BRANCH}"; fi # used if the repo is in a detached head state if [ -z "${GIT_PROMPT_STAGED+x}" ]; then GIT_PROMPT_STAGED="${Red}● "; fi # the number of staged files/directories if [ -z "${GIT_PROMPT_CONFLICTS+x}" ]; then GIT_PROMPT_CONFLICTS="${Red}✖ "; fi # the number of files in conflict if [ -z "${GIT_PROMPT_CHANGED+x}" ]; then GIT_PROMPT_CHANGED="${Blue}✚ "; fi # the number of changed files From 7fb605e570028b7e0a164ae76d2665c2958154fb Mon Sep 17 00:00:00 2001 From: Gek Siong Low Date: Sun, 19 Apr 2020 20:28:35 +0800 Subject: [PATCH 34/40] Add support for zsh --- git-prompt-help.sh | 8 +++--- gitprompt.sh | 28 ++++++++++++--------- gitstatus.sh | 8 +++--- prompt-colors.sh | 54 ++++++++++++++++++++++++++++++++++------- themes/Default.bgptheme | 6 +++++ 5 files changed, 76 insertions(+), 28 deletions(-) diff --git a/git-prompt-help.sh b/git-prompt-help.sh index 0b93950e..6f2f8f83 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -86,10 +86,10 @@ git_prompt_color_samples() { local x=0 while (( x < 8 )) ; do - showColor "${ColorNames[x]}" - showColor "Dim${ColorNames[x]}" - showColor "Bold${ColorNames[x]}" - showColor "Bright${ColorNames[x]}" + showColor "${ColorNames[@]:$x:1}" + showColor "Dim${ColorNames[@]:$x:1}" + showColor "Bold${ColorNames[@]:$x:1}" + showColor "Bright${ColorNames[@]:$x:1}" (( x++ )) done } diff --git a/gitprompt.sh b/gitprompt.sh index 06d08e1b..312ba9f4 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# bash/zsh cross compatibility notes: +# - always use ${array[@]:offset:length} syntax for array indexing + function async_run() { { eval "$@" &> /dev/null @@ -507,6 +510,9 @@ function updatePrompt() { local PROMPT_END local EMPTY_PROMPT local Blue="\[\033[0;34m\]" + if [ -n $ZSH_VERSION ]; then + Blue='%{fg[blue]%}' + fi git_prompt_config @@ -526,33 +532,33 @@ function updatePrompt() { local -a git_status_fields while IFS=$'\n' read -r line; do git_status_fields+=("${line}"); done < <("${__GIT_STATUS_CMD}" 2>/dev/null) - export GIT_BRANCH=$(replaceSymbols "${git_status_fields[0]}") + export GIT_BRANCH=$(replaceSymbols "${git_status_fields[@]:0:1}") if [[ $__GIT_PROMPT_SHOW_TRACKING != "0" ]]; then - local GIT_REMOTE="$(replaceSymbols "${git_status_fields[1]}")" + local GIT_REMOTE="$(replaceSymbols "${git_status_fields[@]:1:1}")" if [[ "." == "${GIT_REMOTE}" ]]; then unset GIT_REMOTE fi fi - local GIT_REMOTE_USERNAME_REPO="$(replaceSymbols "${git_status_fields[2]}")" + local GIT_REMOTE_USERNAME_REPO="$(replaceSymbols "${git_status_fields[@]:2:1}")" if [[ "." == "${GIT_REMOTE_USERNAME_REPO}" ]]; then unset GIT_REMOTE_USERNAME_REPO fi local GIT_FORMATTED_UPSTREAM - local GIT_UPSTREAM_PRIVATE="${git_status_fields[3]}" + local GIT_UPSTREAM_PRIVATE="${git_status_fields[@]:3:1}" if [[ "${__GIT_PROMPT_SHOW_UPSTREAM:-0}" != "1" || "^" == "${GIT_UPSTREAM_PRIVATE}" ]]; then unset GIT_FORMATTED_UPSTREAM else GIT_FORMATTED_UPSTREAM="${GIT_PROMPT_UPSTREAM//_UPSTREAM_/${GIT_UPSTREAM_PRIVATE}}" fi - local GIT_STAGED="${git_status_fields[4]}" - local GIT_CONFLICTS="${git_status_fields[5]}" - local GIT_CHANGED="${git_status_fields[6]}" - local GIT_UNTRACKED="${git_status_fields[7]}" - local GIT_STASHED="${git_status_fields[8]}" - local GIT_CLEAN="${git_status_fields[9]}" - local GIT_DETACHED_HEAD="${git_status_fields[10]}" + local GIT_STAGED="${git_status_fields[@]:4:1}" + local GIT_CONFLICTS="${git_status_fields[@]:5:1}" + local GIT_CHANGED="${git_status_fields[@]:6:1}" + local GIT_UNTRACKED="${git_status_fields[@]:7:1}" + local GIT_STASHED="${git_status_fields[@]:8:1}" + local GIT_CLEAN="${git_status_fields[@]:9:1}" + local GIT_DETACHED_HEAD="${git_status_fields[@]:10:1}" local NEW_PROMPT="${EMPTY_PROMPT}" if [[ "${#git_status_fields[@]}" -gt 0 ]]; then diff --git a/gitstatus.sh b/gitstatus.sh index d35e3f43..bce54d3c 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -131,7 +131,7 @@ if (( num_changed == 0 && num_staged == 0 && num_untracked == 0 && num_stashed = fi IFS="^" read -ra branch_fields <<< "${branch_line/\#\# }" -branch="${branch_fields[0]}" +branch="${branch_fields[@]:0:1}" remote="" upstream="" @@ -139,12 +139,12 @@ detached_head=0 if [[ "${branch}" == *"Initial commit on"* ]]; then IFS=" " read -ra fields <<< "${branch}" - branch="${fields[3]}" + branch="${fields[@]:3:1}" remote="_NO_REMOTE_TRACKING_" remote_url='.' elif [[ "${branch}" == *"No commits yet on"* ]]; then IFS=" " read -ra fields <<< "${branch}" - branch="${fields[4]}" + branch="${fields[@]:4:1}" remote="_NO_REMOTE_TRACKING_" remote_url='.' elif [[ "${branch}" == *"no branch"* ]]; then @@ -162,7 +162,7 @@ else remote_url='.' else IFS="[,]" read -ra remote_fields <<< "${branch_fields[1]}" - upstream="${remote_fields[0]}" + upstream="${remote_fields[@]:0:1}" for remote_field in "${remote_fields[@]}"; do if [[ "${remote_field}" == "ahead "* ]]; then num_ahead="${remote_field:6}" diff --git a/prompt-colors.sh b/prompt-colors.sh index c8794a68..ac282255 100644 --- a/prompt-colors.sh +++ b/prompt-colors.sh @@ -4,6 +4,10 @@ # source this file to get color definitions # are also printed to STDERR. +# bash/zsh cross compatibility notes: +# - using colors modules to set colors in zsh, please autoload it +# - Dim colors, Intense Black not supported in zsh + define_color_names() { ColorNames=( Black Red Green Yellow Blue Magenta Cyan White ) @@ -34,13 +38,23 @@ define_color_names() { local attrname="${1}" local attrcode="${2}" while (( x < 8 )) ; do - local colorname="${ColorNames[x]}" - local fgcolorcode="${FgColors[x]}" - local bgcolorcode="${BgColors[x]}" + local colorname="${ColorNames[@]:$x:1}" + local fgcolorcode="${FgColors[@]:$x:1}" + local bgcolorcode="${BgColors[@]:$x:1}" longcolorname="${attrname}${colorname}" - _def_color "${longcolorname}" "${attrcode}" "${fgcolorcode}" - _def_color "${longcolorname}Fg" "${attrcode}" "${fgcolorcode}" - _def_color "${longcolorname}Bg" "${attrcode}" "${bgcolorcode}" + + if [ -n "$ZSH_VERSION" ]; then + # zsh + lowercolorname=$(echo $colorname | tr '[A-Z]' '[a-z]') + _def_color_zsh "${longcolorname}" "${attrcode}" "${lowercolorname}" "fg" + _def_color_zsh "${longcolorname}Fg" "${attrcode}" "${lowercolorname}" "fg" + _def_color_zsh "${longcolorname}Bg" "${attrcode}" "${lowercolorname}" "bg" + else + # bash + _def_color "${longcolorname}" "${attrcode}" "${fgcolorcode}" + _def_color "${longcolorname}Fg" "${attrcode}" "${fgcolorcode}" + _def_color "${longcolorname}Bg" "${attrcode}" "${bgcolorcode}" + fi (( x++ )) done } @@ -62,14 +76,36 @@ define_color_names() { eval "${def}" } + # def_color_zsh NAME ATTRCODE COLORNAME FG|BG + _def_color_zsh() { + if [ "${3}" = "0" ]; then + local def="${1}=\"%{\$reset_color%}\"" + else + case ${2} in + 1) # bold color + local def="${1}=\"%{\$${4}_bold[${3}]%}\"" + ;; + *) + local def="${1}=\"%{\$${4}[${3}]%}\"" + ;; + esac + fi + eval "${def}" + } + + _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 - + if [ -n "$ZSH_VERSION" ]; then + _def_color_zsh IntenseBlack 0 90 + _def_color_zsh ResetColor 0 0 + else + _def_color IntenseBlack 0 90 + _def_color ResetColor 0 0 + fi } # do the color definitions only once diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index c7b1f22d..4ba494ec 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -33,6 +33,12 @@ unset_git_prompt_colors() { define_helpers() { Time12a="\$(date +%H:%M)" PathShort="\w"; + NewLine="\n" + + if [ -n "$ZSH_VERSION" ]; then + PathShort="%~" + NewLine=$'\n' + fi } define_undefined_git_prompt_colors() { From 18103a0969b11785a006da05e487a4cecb69fe96 Mon Sep 17 00:00:00 2001 From: Gek Siong Low Date: Fri, 8 May 2020 18:19:43 +0800 Subject: [PATCH 35/40] Fix 'can't manipulate jobs in subshell' error in zsh --- gitprompt.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 312ba9f4..75d8ceed 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -9,7 +9,15 @@ function async_run() { }& } -function set_git_prompt_dir() { +function async_run_zsh() { + { + eval "$@" &> /dev/null + }&! +} + + +function git_prompt_dir() { + # 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 __GIT_PROMPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) @@ -441,8 +449,12 @@ function checkUpstream() { then if [[ -n $(git remote show) ]]; then ( - async_run "GIT_TERMINAL_PROMPT=0 git fetch --quiet" - disown -h + if [ -n $ZSH_VERSION ]; then + async_run_zsh "GIT_TERMINAL_PROMPT=0 git fetch --quiet" + else + async_run "GIT_TERMINAL_PROMPT=0 git fetch --quiet" + disown -h + fi ) fi fi From 04a9901eb6d42f2f0284ffadf0eb94673733268a Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Mon, 18 May 2020 16:56:23 -0700 Subject: [PATCH 36/40] Correct issues with default theme on zsh - Use added `NewLine` variable for zsh-specific newline - `Time12a` variant added for zsh --- themes/Default.bgptheme | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index 4ba494ec..fbc22abd 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -36,6 +36,7 @@ define_helpers() { NewLine="\n" if [ -n "$ZSH_VERSION" ]; then + Time12a="%T" PathShort="%~" NewLine=$'\n' fi @@ -90,8 +91,8 @@ 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+x}" ]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"; fi if [ -z "${GIT_PROMPT_START_ROOT+x}" ]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi - if [ -z "${GIT_PROMPT_END_USER+x}" ]; then GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ "; fi - if [ -z "${GIT_PROMPT_END_ROOT+x}" ]; then GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # "; fi + if [ -z "${GIT_PROMPT_END_USER+x}" ]; then GIT_PROMPT_END_USER=" ${NewLine}${White}${Time12a}${ResetColor} $ "; fi + if [ -z "${GIT_PROMPT_END_ROOT+x}" ]; then GIT_PROMPT_END_ROOT=" ${NewLine}${White}${Time12a}${ResetColor} # "; fi # Please do not add colors to these symbols if [ -z ${GIT_PROMPT_SYMBOLS_AHEAD+x} ]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin" From 9abaa396d8981064627933c8f45ecdcc57dc2845 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Mon, 30 Nov 2020 18:23:49 -0800 Subject: [PATCH 37/40] Quote use of `$ZSH_VERSION` Without quotes, the test will succeed even when the variable is not defined. --- gitprompt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 75d8ceed..55b772c2 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -449,7 +449,7 @@ function checkUpstream() { then if [[ -n $(git remote show) ]]; then ( - if [ -n $ZSH_VERSION ]; then + if [ -n "$ZSH_VERSION" ]; then async_run_zsh "GIT_TERMINAL_PROMPT=0 git fetch --quiet" else async_run "GIT_TERMINAL_PROMPT=0 git fetch --quiet" @@ -522,7 +522,7 @@ function updatePrompt() { local PROMPT_END local EMPTY_PROMPT local Blue="\[\033[0;34m\]" - if [ -n $ZSH_VERSION ]; then + if [ -n "$ZSH_VERSION" ]; then Blue='%{fg[blue]%}' fi From 8300c6ef40f40a6fa2dff4a968c28bb4a30fdc92 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Mon, 30 Nov 2020 18:56:51 -0800 Subject: [PATCH 38/40] Fix bash compatibility The use of zsh `&!` syntax was causing bash to die in script parsing, even though this never gets executed. This adds `true` as a dummy command to get past parsing and allow both bash and zsh to execute the script. --- gitprompt.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 55b772c2..f23a1346 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -12,7 +12,9 @@ function async_run() { function async_run_zsh() { { eval "$@" &> /dev/null - }&! + + # `true` is used here to allow bash to parse the script, as the zsh `&!` syntax will otherwise stop parsing prior to any execution. + }&! true } From 212b9dbcd4322988a98d09adbeaf6ff902f06635 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Mon, 20 Feb 2023 17:05:21 -0700 Subject: [PATCH 39/40] Restore upstream `set_git_prompt_dir` This function was renamed upstream, but the rename was clobbered during rebase. --- gitprompt.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index f23a1346..e3a735d8 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -18,8 +18,7 @@ function async_run_zsh() { } -function git_prompt_dir() { - # assume the gitstatus.sh is in the same directory as this script +function set_git_prompt_dir() { # code thanks to http://stackoverflow.com/questions/59895 if [ -z "$__GIT_PROMPT_DIR" ]; then __GIT_PROMPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) From 8695c70e593b341713e4c66f98d31bac3a397746 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Mon, 20 Feb 2023 17:06:08 -0700 Subject: [PATCH 40/40] Fix improper use of `==` with `[` `==` is only (semi-)portable when used with `[[`. --- gitprompt.sh | 4 ++-- tests/test-non-git-ps1.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index e3a735d8..999547ee 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -713,12 +713,12 @@ function add_prompt_command() { return 0 fi - if [ -z "$PROMPT_COMMAND" ]; then + if [[ -z "$PROMPT_COMMAND" ]]; then PROMPT_COMMAND="$new_entry" return 0 fi - if [ "$insert_before" == "true" ]; then + if [[ "$insert_before" == "true" ]]; then PROMPT_COMMAND="${new_entry};${PROMPT_COMMAND}" else PROMPT_COMMAND="${PROMPT_COMMAND};${new_entry}" diff --git a/tests/test-non-git-ps1.sh b/tests/test-non-git-ps1.sh index f970e04c..130eeece 100755 --- a/tests/test-non-git-ps1.sh +++ b/tests/test-non-git-ps1.sh @@ -23,7 +23,7 @@ function test_original_prompt_is_restored() { # Navigate back into the repo cd "$REPO_ROOT" run_prompt_command - if [ "$PS1" == "$" ]; then + if [[ "$PS1" == "$" ]]; then echo "PS1: $PS1 == \$" return 1 fi