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/README.md b/README.md index 8f7ecff7..5f988e45 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 @@ -146,28 +115,29 @@ cp gitprompt.fish ~/.config/fish/functions/fish_prompt.fish ```sh - # Set config variables first - GIT_PROMPT_ONLY_IN_REPO=1 +# Set config variables first +GIT_PROMPT_ONLY_IN_REPO=1 - # GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status - # GIT_PROMPT_IGNORE_SUBMODULES=1 # uncomment to avoid searching for changed files in submodules - # GIT_PROMPT_WITH_VIRTUAL_ENV=0 # uncomment to avoid setting virtual environment infos for node/python/conda environments +# GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status +# GIT_PROMPT_IGNORE_SUBMODULES=1 # uncomment to avoid searching for changed files in submodules +# GIT_PROMPT_WITH_VIRTUAL_ENV=0 # uncomment to avoid setting virtual environment infos for node/python/conda environments +# GIT_PROMPT_VIRTUAL_ENV_AFTER_PROMPT=1 # uncomment to place virtual environment infos between prompt and git status (instead of left to the prompt) - # GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch - # GIT_PROMPT_SHOW_UNTRACKED_FILES=normal # can be no, normal or all; determines counting of untracked files +# GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch +# GIT_PROMPT_SHOW_UNTRACKED_FILES=normal # can be no, normal or all; determines counting of untracked files - # GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=0 # uncomment to avoid printing the number of changed files +# GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=0 # uncomment to avoid printing the number of changed files - # GIT_PROMPT_STATUS_COMMAND=gitstatus_pre-1.7.10.sh # uncomment to support Git older than 1.7.10 +# GIT_PROMPT_STATUS_COMMAND=gitstatus_pre-1.7.10.sh # uncomment to support Git older than 1.7.10 - # GIT_PROMPT_START=... # uncomment for custom prompt start sequence - # GIT_PROMPT_END=... # uncomment for custom prompt end sequence +# GIT_PROMPT_START=... # uncomment for custom prompt start sequence +# GIT_PROMPT_END=... # uncomment for custom prompt end sequence - # as last entry source the gitprompt script - # GIT_PROMPT_THEME=Custom # use custom theme specified in file GIT_PROMPT_THEME_FILE (default ~/.git-prompt-colors.sh) - # GIT_PROMPT_THEME_FILE=~/.git-prompt-colors.sh - # GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme - source ~/.bash-git-prompt/gitprompt.sh +# as last entry source the gitprompt script +# GIT_PROMPT_THEME=Custom # use custom theme specified in file GIT_PROMPT_THEME_FILE (default ~/.git-prompt-colors.sh) +# GIT_PROMPT_THEME_FILE=~/.git-prompt-colors.sh +# GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme +source ~/.bash-git-prompt/gitprompt.sh ``` You can set the `GIT_PROMPT_SHOW_UNTRACKED_FILES` variable to `no` or `normal` to speed things up if you have lots of @@ -189,7 +159,7 @@ GIT_PROMPT_THEME=Solarized If you set `GIT_PROMPT_THEME` to `Custom`, then the `.git-prompt-colors.sh` in the home directory will be used. This file can now be generated with the command `git_prompt_make_custom_theme []`. 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) @@ -382,6 +352,9 @@ Please leave a comment on the issue, that you want to fix it, so others know, th Pull requests are welcome. I will check them and merge them, if I think they help the project. +## Similar projects +https://github.com/ohmybash/oh-my-bash + ## Donations I accept tips through [Flattr][flattr]. 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 diff --git a/git-prompt-help.sh b/git-prompt-help.sh index ffa3da57..6f2f8f83 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -5,18 +5,19 @@ 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: ${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: @@ -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 < /dev/null }& } -function git_prompt_dir() { - # assume the gitstatus.sh is in the same directory as this script +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 +} + + +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 +92,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 +115,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 +158,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 +211,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$//' } @@ -280,7 +281,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}" @@ -292,7 +297,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 @@ -303,6 +307,7 @@ function git_prompt_config() { function setLastCommandState() { GIT_PROMPT_LAST_COMMAND_STATE="${?}" + return ${GIT_PROMPT_LAST_COMMAND_STATE} } function we_are_on_repo() { @@ -314,12 +319,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() { @@ -354,9 +358,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 @@ -374,6 +381,11 @@ function setGitPrompt() { fi unset OLD_GIT_PROMPT_IGNORE_SUBMODULES + if [[ -z "${GIT_PROMPT_SHOW_TRACKING+x}" ]]; 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 @@ -438,8 +450,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 @@ -456,8 +472,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 @@ -472,11 +489,33 @@ 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}" } +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 @@ -484,15 +523,19 @@ 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 - __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_TRACKING=${GIT_PROMPT_SHOW_TRACKING:-1} 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 @@ -502,31 +545,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]}") - local GIT_REMOTE="$(replaceSymbols "${git_status_fields[1]}")" - if [[ "." == "${GIT_REMOTE}" ]]; then - unset GIT_REMOTE + export GIT_BRANCH=$(replaceSymbols "${git_status_fields[@]:0:1}") + if [[ $__GIT_PROMPT_SHOW_TRACKING != "0" ]]; then + 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_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 @@ -541,14 +586,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 @@ -591,7 +630,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 @@ -655,47 +698,47 @@ 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" +} - 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 +function add_to_end_of_prompt_command() { + add_prompt_command "$1" "false" +} + +function gp_install_prompt { + make_prompt_command_clean + 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" } 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 diff --git a/gitstatus.sh b/gitstatus.sh index 7cbda63a..bce54d3c 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 @@ -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++)) ;; @@ -132,26 +131,30 @@ 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="" +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 tag=$( git describe --tags --exact-match ) if [[ -n "${tag}" ]]; then - branch="${tag}" + 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 @@ -159,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}" @@ -184,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}" \ @@ -194,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/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/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..effa22c4 --- /dev/null +++ b/tests/base.sh @@ -0,0 +1,25 @@ + +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 +} + +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..130eeece --- /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" 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" diff --git a/themes/BlackOrWhite.bgptheme b/themes/BlackOrWhite.bgptheme new file mode 100644 index 00000000..81611e5e --- /dev/null +++ b/themes/BlackOrWhite.bgptheme @@ -0,0 +1,460 @@ +###################################################################################### +# 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 text is using the terminal text color. +# Git branch state part is using similar colors like git (red, green). +# Also, configurable which part to display and where to show icons. +# Nerd fonts are needed to display icons. +# +# Settings: +# ========= +# +# Color options: +# -------------- +# Variable name: GIT_PROMPT_BLACK_OR_WHITE_THEME_PS1_COLOR +# Possible values: +# - black (default) +# - white +# +# Command prompt styles: +# ---------------------- +# Variable name: GIT_PROMPT_BLACK_OR_WHITE_THEME_STYLE +# Possible values: +# - bubbles (default) +# - bubbles_with_double_line +# - powerline +# +# 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. +# +# 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_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)──(~) +# └─• +# +# Display time instead of user and hostname +# ┌─(10:58:58)──(~) +# └─• +# +# Display root user prompt +# ┌─(11:08:06)──(/home/root) +# └─(!)─• +# +# Display git branch with or without 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) +# └─• +# +# 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   ~    +# └─• +# +# ┌─    user   hostname   ~/.bash-git-prompt      master  | 1 +# └─• +# +###################################################################################### +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="BlackOrWhite" + + 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 ) + # Default + ;; + + white ) + PS1Color="${PS1BoldWhiteColor}" + PS1SartEndColor="${PS1BoldWhiteColor}" + ;; + esac + + 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="" + # 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="⚑${ExtraSpaceAfterIcon}" + local CleanIcon="✔" + local AheadIcon="↑·" + local BehindIcon="↓·" + local PrehashIcon=":" + local NoRemoteTrackingIcon="L" + + 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}" + ;; + + 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 [[ $SectionAddedCounter -eq 0 ]]; then + GIT_PROMPT_START_USER+="\w" + fi + + GIT_PROMPT_START_USER+="${PS1Color}${PromptStartSuffix}${PS1ResetColor}" + + if [[ "$GIT_PROMPT_BLACK_OR_WHITE_THEME_STYLE" == "powerline" ]]; then + GIT_PROMPT_START_USER+=" " + fi + + GIT_PROMPT_LEADING_SPACE=0 + + 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="${PS1GreenColor}${StagedIcon}" + GIT_PROMPT_CONFLICTS="${PS1RedColor}${ConflictsIcon}" + GIT_PROMPT_CHANGED="${PS1RedColor}${ChangedIcon}" + + GIT_PROMPT_REMOTE="${PS1Color}${RemoteIcon}" + GIT_PROMPT_UNTRACKED="${PS1Color}${UntrackedIcon}" + GIT_PROMPT_STASHED="${PS1Color}${StashedIcon}" + GIT_PROMPT_CLEAN="${PS1GreenColor}${CleanIcon}" + + GIT_PROMPT_COMMAND_OK="${PS1GreenColor}${CommandOkIcon}" + GIT_PROMPT_COMMAND_FAIL="${PS1RedColor}${CommandFailIcon}-_LAST_COMMAND_STATE_" + + GIT_PROMPT_SYMBOLS_AHEAD="${PS1Color}${AheadIcon}" + GIT_PROMPT_SYMBOLS_BEHIND="${PS1Color}${BehindIcon}" + GIT_PROMPT_SYMBOLS_PREHASH="${PrehashIcon}" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="${PS1Color}${NoRemoteTrackingIcon}" + + GIT_PROMPT_VIRTUALENV="${PS1Color}${PS1ResetColor}[${PS1Color}_VIRTUALENV_${PS1ResetColor}] " + + GIT_PROMPT_UPSTREAM="${PS1Color} ${PS1ResetColor}{${PS1Color}_UPSTREAM_${PS1ResetColor}}" + + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER="${ResetColor}${PS1SartEndColor}\n${PromptEndUser}${ResetColor} " + GIT_PROMPT_END_ROOT="${ResetColor}${PS1SartEndColor}\n${PromptEndRoot}${ResetColor} " +} + +reload_git_prompt_colors "BlackOrWhite" 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 diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index a43a5f17..fbc22abd 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 @@ -25,12 +26,20 @@ 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 } define_helpers() { Time12a="\$(date +%H:%M)" PathShort="\w"; + NewLine="\n" + + if [ -n "$ZSH_VERSION" ]; then + Time12a="%T" + PathShort="%~" + NewLine=$'\n' + fi } define_undefined_git_prompt_colors() { @@ -43,7 +52,8 @@ 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_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 @@ -81,13 +91,14 @@ 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" 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 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" 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" + 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" + 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}]" 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'