From 882bc8ea46cfd419bcd05123c53c91b9114ca2e6 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 20 Sep 2014 21:56:35 +0200 Subject: [PATCH 1/9] Added first thought on themes --- gitprompt.sh | 69 ++++++++++++++++++++++++-- themes/Default.bgptheme | 1 + themes/NoLastCommandIndicator.bgptheme | 50 +++++++++++++++++++ themes/Original.bgptheme | 50 +++++++++++++++++++ 4 files changed, 165 insertions(+), 5 deletions(-) create mode 120000 themes/Default.bgptheme create mode 100644 themes/NoLastCommandIndicator.bgptheme create mode 100644 themes/Original.bgptheme diff --git a/gitprompt.sh b/gitprompt.sh index b5180559..8f43443c 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -22,6 +22,68 @@ function git_prompt_dir() fi } +function echoc() { + echo -e "${1}$2${ResetColor}" | sed 's/\\\]//g' | sed 's/\\\[//g' +} + +function get_theme() +{ + if [[ -z ${GIT_PROMPT_THEME} ]]; then + GIT_PROMPT_THEME="Default" + __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + else + if [[ "${GIT_PROMPT_THEME}" = "Custom" ]]; then + GIT_PROMPT_THEME="Custom" + __GIT_PROMPT_THEME_FILE="${HOME}/.git-prompt-colors.sh" + if [[ !(-r $__GIT_PROMPT_THEME_FILE) ]]; then + GIT_PROMPT_THEME="Default" + __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + fi + else + local theme="" + + # use default theme, if theme was not found + for themefile in `ls $__GIT_PROMPT_DIR/themes`; do + if [[ "${themefile}" = "${GIT_PROMPT_THEME}.bgptheme" ]]; then + theme=$GIT_PROMPT_THEME + fi + done + + if [[ "${theme}" = "" ]]; then + GIT_PROMPT_THEME="Default" + fi + + __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/${GIT_PROMPT_THEME}.bgptheme" + fi + fi + +} + +function git_prompt_list_themes() +{ + local oldTheme + local oldThemeFile + + git_prompt_dir + get_theme + + for themefile in `ls $__GIT_PROMPT_DIR/themes`; do + local theme="$(basename $themefile .bgptheme)" + + if [[ "${GIT_PROMPT_THEME}" = "${theme}" ]]; then + echoc ${Red} "*${theme}" + else + echo $theme + fi + done + + if [[ "${GIT_PROMPT_THEME}" = "Custom" ]]; then + echoc ${Magenta} "*Custom" + else + echoc ${Blue} "Custom" + fi +} + # gp_set_file_var ENVAR SOMEFILE # # If ENVAR is set, check that it's value exists as a readable file. Otherwise, @@ -99,11 +161,8 @@ function git_prompt_config() # source the user's ~/.git-prompt-colors.sh file, or the one that should be # sitting in the same directory as this script - if gp_set_file_var __GIT_PROMPT_COLORS_FILE git-prompt-colors.sh ; then - source "$__GIT_PROMPT_COLORS_FILE" - else - echo 1>&2 "Cannot find git-prompt-colors.sh!" - fi + get_theme + source "$__GIT_PROMPT_THEME_FILE" if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK"; diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme new file mode 120000 index 00000000..8e0b4a10 --- /dev/null +++ b/themes/Default.bgptheme @@ -0,0 +1 @@ +Original.bgptheme \ No newline at end of file diff --git a/themes/NoLastCommandIndicator.bgptheme b/themes/NoLastCommandIndicator.bgptheme new file mode 100644 index 00000000..b6309b30 --- /dev/null +++ b/themes/NoLastCommandIndicator.bgptheme @@ -0,0 +1,50 @@ +# These are the color definitions used by gitprompt.sh + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Red}●" # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict + GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files + + GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldBlue}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + # Please do not add colors to these symbols + GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" + GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" + GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi diff --git a/themes/Original.bgptheme b/themes/Original.bgptheme new file mode 100644 index 00000000..9d6a7ed6 --- /dev/null +++ b/themes/Original.bgptheme @@ -0,0 +1,50 @@ +# These are the color definitions used by gitprompt.sh + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Red}●" # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict + GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files + + GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldBlue}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + # Please do not add colors to these symbols + GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" + GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" + GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi From 71810b95f5a4be352d0e640dd1efc172984686e5 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 21 Sep 2014 13:08:21 +0200 Subject: [PATCH 2/9] moved themes around --- git-prompt-colors.sh | 50 -------------------------- git-prompt-help.sh | 4 +-- themes/Default.bgptheme | 1 - themes/NoLastCommandIndicator.bgptheme | 2 +- themes/Original.bgptheme | 50 -------------------------- 5 files changed, 3 insertions(+), 104 deletions(-) delete mode 100644 git-prompt-colors.sh delete mode 120000 themes/Default.bgptheme delete mode 100644 themes/Original.bgptheme diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh deleted file mode 100644 index 9d6a7ed6..00000000 --- a/git-prompt-colors.sh +++ /dev/null @@ -1,50 +0,0 @@ -# These are the color definitions used by gitprompt.sh - -define_git_prompt_colors() { - Time12a="\$(date +%H:%M)" - PathShort="\w" - - # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item - - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory - GIT_PROMPT_STAGED="${Red}●" # the number of staged files/directories - GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict - GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files - - GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind - GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs - GIT_PROMPT_STASHED="${BoldBlue}⚑ " # the number of stashed files/dir - GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo - - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ - # will be replaced with the exit code of the last command - # e.g. - # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - - GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 - - # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with - # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL - GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " - GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " - - # Please do not add colors to these symbols - GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" - GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" - GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found -} - -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors -fi diff --git a/git-prompt-help.sh b/git-prompt-help.sh index 8b9b390d..d1fe7510 100755 --- a/git-prompt-help.sh +++ b/git-prompt-help.sh @@ -3,8 +3,8 @@ # being displayed. git_prompt_help() { - source prompt-colors.sh - source git-prompt-colors.sh + source ${__GIT_PROMPT_DIR}/prompt-colors.sh + source themes/Default.bgptheme cat <|] diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme deleted file mode 120000 index 8e0b4a10..00000000 --- a/themes/Default.bgptheme +++ /dev/null @@ -1 +0,0 @@ -Original.bgptheme \ No newline at end of file diff --git a/themes/NoLastCommandIndicator.bgptheme b/themes/NoLastCommandIndicator.bgptheme index b6309b30..751b7ed0 100644 --- a/themes/NoLastCommandIndicator.bgptheme +++ b/themes/NoLastCommandIndicator.bgptheme @@ -1,4 +1,4 @@ -# These are the color definitions used by gitprompt.sh +# This is the default theme for gitprompt.sh without the indicator of the last command state define_git_prompt_colors() { Time12a="\$(date +%H:%M)" diff --git a/themes/Original.bgptheme b/themes/Original.bgptheme deleted file mode 100644 index 9d6a7ed6..00000000 --- a/themes/Original.bgptheme +++ /dev/null @@ -1,50 +0,0 @@ -# These are the color definitions used by gitprompt.sh - -define_git_prompt_colors() { - Time12a="\$(date +%H:%M)" - PathShort="\w" - - # These are the color definitions used by gitprompt.sh - GIT_PROMPT_PREFIX="[" # start of the git info string - GIT_PROMPT_SUFFIX="]" # the end of the git info string - GIT_PROMPT_SEPARATOR="|" # separates each item - - GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory - GIT_PROMPT_STAGED="${Red}●" # the number of staged files/directories - GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict - GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files - - GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind - GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs - GIT_PROMPT_STASHED="${BoldBlue}⚑ " # the number of stashed files/dir - GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo - - # For the command indicator, the placeholder _LAST_COMMAND_STATE_ - # will be replaced with the exit code of the last command - # e.g. - # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 - # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 - - GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 - - # template for displaying the current virtual environment - # use the placeholder _VIRTUALENV_ will be replaced with - # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) - GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " - - # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL - GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" - GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" - GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " - GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " - - # Please do not add colors to these symbols - GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" - GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" - GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found -} - -if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then - define_git_prompt_colors -fi From e31c91802c431dddfc04d9c3d064400562e9cbbd Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 21 Sep 2014 13:08:35 +0200 Subject: [PATCH 3/9] Readded Default theme --- themes/Default.bgptheme | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 themes/Default.bgptheme diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme new file mode 100644 index 00000000..685ab1c1 --- /dev/null +++ b/themes/Default.bgptheme @@ -0,0 +1,50 @@ +# This is the default theme for gitprompt.sh + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Red}●" # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict + GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files + + GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldBlue}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + # Please do not add colors to these symbols + GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" + GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" + GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi From 09248274652c3db2ec77cc1a6a107401b0112596 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 21 Sep 2014 13:08:59 +0200 Subject: [PATCH 4/9] Added theme optimised for the "Solarized Dark" theme --- themes/SolarizedDark.bgptheme | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 themes/SolarizedDark.bgptheme diff --git a/themes/SolarizedDark.bgptheme b/themes/SolarizedDark.bgptheme new file mode 100644 index 00000000..3c186a6a --- /dev/null +++ b/themes/SolarizedDark.bgptheme @@ -0,0 +1,50 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" color scheme + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Yellow}●" # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict + GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files + + GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${Green}✔" # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " + + # Please do not add colors to these symbols + GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" + GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" + GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi From becb66cf0f46b4f1011ba407459c86a5ae0b743b Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 21 Sep 2014 13:09:25 +0200 Subject: [PATCH 5/9] Added function to derive a custom theme from a given theme --- gitprompt.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gitprompt.sh b/gitprompt.sh index 8f43443c..566b79f4 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -84,6 +84,30 @@ function git_prompt_list_themes() fi } +function git_prompt_make_custom_theme() { + if [[ -r "${HOME}/.git-prompt-colors.sh" ]]; then + echoc ${Red} "You alread have created a custom theme!" + else + git_prompt_dir + + local base="Default" + if [[ -n $1 && -r "${__GIT_PROMPT_DIR}/themes/${1}.bgptheme" ]]; then + base=$1 + echoc ${Green} "Using theme ${Magenta}\"${base}\"${Green} as base theme!" + else + echoc ${Green} "Using theme ${Magenta}\"Default\"${Green} as base theme!" + fi + + if [[ "${base}" = "Custom" ]]; then + echoc ${Red} "You cannot use the custom theme as base" + else + echoc ${Green} "Creating new cutom theme in \"${HOME}/.git-prompt-colors.sh\"" + echoc ${DimYellow} "Please add ${Magenta}\"GIT_PROMPT_THEME=Custom\"${DimYellow} to your .bashrc to use this theme" + cp "${__GIT_PROMPT_DIR}/themes/${base}.bgptheme" "${HOME}/.git-prompt-colors.sh" + fi + fi +} + # gp_set_file_var ENVAR SOMEFILE # # If ENVAR is set, check that it's value exists as a readable file. Otherwise, From 467ca14bcde72ee15c92e313f9517bf04315e09a Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sun, 21 Sep 2014 13:16:37 +0200 Subject: [PATCH 6/9] Renamed theme SolarizedDark to Solarized, because it matches both variants --- themes/{SolarizedDark.bgptheme => Solarized.bgptheme} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename themes/{SolarizedDark.bgptheme => Solarized.bgptheme} (98%) diff --git a/themes/SolarizedDark.bgptheme b/themes/Solarized.bgptheme similarity index 98% rename from themes/SolarizedDark.bgptheme rename to themes/Solarized.bgptheme index 3c186a6a..9a936cf0 100644 --- a/themes/SolarizedDark.bgptheme +++ b/themes/Solarized.bgptheme @@ -1,4 +1,4 @@ -# This theme for gitprompt.sh is optimized for the "Solarized Dark" color scheme +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes define_git_prompt_colors() { Time12a="\$(date +%H:%M)" From 7b95c937668334e07dc652a633033e246fce12d6 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 4 Oct 2014 21:21:47 +0200 Subject: [PATCH 7/9] Added themes without display of exit state for Solarized theme, added tweaked themes for Ubuntu terminal fonts (see #77) --- themes/Default.bgptheme | 2 +- ....bgptheme => Default_NoExitState.bgptheme} | 3 +- themes/Default_NoExitState_Ubuntu.bgptheme | 52 +++++++++++++++++++ themes/Default_Ubuntu.bgptheme | 51 ++++++++++++++++++ themes/Solarized.bgptheme | 5 +- themes/Solarized_NoExitState.bgptheme | 51 ++++++++++++++++++ themes/Solarized_NoExitState_Ubuntu.bgptheme | 52 +++++++++++++++++++ themes/Solarized_Ubuntu.bgptheme | 51 ++++++++++++++++++ 8 files changed, 263 insertions(+), 4 deletions(-) rename themes/{NoLastCommandIndicator.bgptheme => Default_NoExitState.bgptheme} (96%) create mode 100644 themes/Default_NoExitState_Ubuntu.bgptheme create mode 100644 themes/Default_Ubuntu.bgptheme create mode 100644 themes/Solarized_NoExitState.bgptheme create mode 100644 themes/Solarized_NoExitState_Ubuntu.bgptheme create mode 100644 themes/Solarized_Ubuntu.bgptheme diff --git a/themes/Default.bgptheme b/themes/Default.bgptheme index 685ab1c1..fbb56ab6 100644 --- a/themes/Default.bgptheme +++ b/themes/Default.bgptheme @@ -26,7 +26,7 @@ define_git_prompt_colors() { # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 # template for displaying the current virtual environment # use the placeholder _VIRTUALENV_ will be replaced with diff --git a/themes/NoLastCommandIndicator.bgptheme b/themes/Default_NoExitState.bgptheme similarity index 96% rename from themes/NoLastCommandIndicator.bgptheme rename to themes/Default_NoExitState.bgptheme index 751b7ed0..e2387494 100644 --- a/themes/NoLastCommandIndicator.bgptheme +++ b/themes/Default_NoExitState.bgptheme @@ -1,4 +1,5 @@ -# This is the default theme for gitprompt.sh without the indicator of the last command state +# This is the default theme for gitprompt.sh +# without the indicator of the last command state define_git_prompt_colors() { Time12a="\$(date +%H:%M)" diff --git a/themes/Default_NoExitState_Ubuntu.bgptheme b/themes/Default_NoExitState_Ubuntu.bgptheme new file mode 100644 index 00000000..1f7a1e76 --- /dev/null +++ b/themes/Default_NoExitState_Ubuntu.bgptheme @@ -0,0 +1,52 @@ +# This is the default theme for gitprompt.sh +# without the indicator of the last command state +# tweaked for Ubuntu terminal fonts + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Red}● " # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict + GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files + + GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}… " # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldBlue}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${BoldGreen}✔ " # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + # Please do not add colors to these symbols + GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" + GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" + GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi diff --git a/themes/Default_Ubuntu.bgptheme b/themes/Default_Ubuntu.bgptheme new file mode 100644 index 00000000..a1b54b05 --- /dev/null +++ b/themes/Default_Ubuntu.bgptheme @@ -0,0 +1,51 @@ +# This is the default theme for gitprompt.sh +# tweaked for Ubuntu terminal fonts + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Red}● " # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict + GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files + + GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}… " # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldBlue}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${BoldGreen}✔ " # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + # Please do not add colors to these symbols + GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" + GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" + GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi diff --git a/themes/Solarized.bgptheme b/themes/Solarized.bgptheme index 9a936cf0..7825fd2b 100644 --- a/themes/Solarized.bgptheme +++ b/themes/Solarized.bgptheme @@ -1,4 +1,5 @@ -# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# tweaked for Ubuntu terminal fonts define_git_prompt_colors() { Time12a="\$(date +%H:%M)" @@ -26,7 +27,7 @@ define_git_prompt_colors() { # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 - GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 # template for displaying the current virtual environment # use the placeholder _VIRTUALENV_ will be replaced with diff --git a/themes/Solarized_NoExitState.bgptheme b/themes/Solarized_NoExitState.bgptheme new file mode 100644 index 00000000..a2108d7b --- /dev/null +++ b/themes/Solarized_NoExitState.bgptheme @@ -0,0 +1,51 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# without the indicator of the last command state + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Yellow}●" # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict + GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files + + GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${Green}✔" # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " + + # Please do not add colors to these symbols + GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" + GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" + GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi diff --git a/themes/Solarized_NoExitState_Ubuntu.bgptheme b/themes/Solarized_NoExitState_Ubuntu.bgptheme new file mode 100644 index 00000000..d8cab5e7 --- /dev/null +++ b/themes/Solarized_NoExitState_Ubuntu.bgptheme @@ -0,0 +1,52 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# without the indicator of the last command state +# tweaked for Ubuntu terminal fonts + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Yellow}● " # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict + GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files + + GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}… " # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${Green}✔ " # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " + + # Please do not add colors to these symbols + GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" + GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" + GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi diff --git a/themes/Solarized_Ubuntu.bgptheme b/themes/Solarized_Ubuntu.bgptheme new file mode 100644 index 00000000..3b7b1462 --- /dev/null +++ b/themes/Solarized_Ubuntu.bgptheme @@ -0,0 +1,51 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# tweaked for Ubuntu terminal fonts + +define_git_prompt_colors() { + Time12a="\$(date +%H:%M)" + PathShort="\w" + + # These are the color definitions used by gitprompt.sh + GIT_PROMPT_PREFIX="[" # start of the git info string + GIT_PROMPT_SUFFIX="]" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Yellow}● " # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict + GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files + + GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED="${Cyan}… " # the number of untracked files/dirs + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${Green}✔ " # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " + + # Please do not add colors to these symbols + GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" + GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" + GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found +} + +if [[ -z "$GIT_PROMPT_SEPARATOR" || -z "$GIT_PROMPT_COMMAND_OK" ]]; then + define_git_prompt_colors +fi From 296a04b76f50ce627fdd684b15e4f4e39e65fead Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 4 Oct 2014 21:33:49 +0200 Subject: [PATCH 8/9] Tweaks for backwards compatibility --- gitprompt.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 5ffe7220..a172acbd 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -28,16 +28,25 @@ function echoc() { function get_theme() { + local CUSTOM_THEME_FILE="${HOME}/.git-prompt-colors.sh" + local DEFAULT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + if [[ -z ${GIT_PROMPT_THEME} ]]; then - GIT_PROMPT_THEME="Default" - __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + if [[ -r $CUSTOM_THEME_FILE ]]; then + GIT_PROMPT_THEME="Custom" + __GIT_PROMPT_THEME_FILE=$CUSTOM_THEME_FILE + else + GIT_PROMPT_THEME="Default" + __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE + fi else if [[ "${GIT_PROMPT_THEME}" = "Custom" ]]; then GIT_PROMPT_THEME="Custom" - __GIT_PROMPT_THEME_FILE="${HOME}/.git-prompt-colors.sh" + __GIT_PROMPT_THEME_FILE=$CUSTOM_THEME_FILE + if [[ !(-r $__GIT_PROMPT_THEME_FILE) ]]; then GIT_PROMPT_THEME="Default" - __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE fi else local theme="" @@ -56,7 +65,6 @@ function get_theme() __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/${GIT_PROMPT_THEME}.bgptheme" fi fi - } function git_prompt_list_themes() From 43a0d72df3af12a2686440f6f9fc512d85c46c03 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Sat, 4 Oct 2014 22:00:13 +0200 Subject: [PATCH 9/9] Updated README --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 756186c0..2fe64fed 100644 --- a/README.md +++ b/README.md @@ -103,11 +103,34 @@ git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt # GIT_PROMPT_END=... # uncomment for custom prompt end sequence # as last entry source the gitprompt script + # GIT_PROMPT_THEME=Custom # use custom .git-prompt-colors.sh + # GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme source ~/.bash-git-prompt/gitprompt.sh ``` - `cd` to a git repository and test it! +#### Themes + +The most settings are now stored in theme files. To select a theme, set the variable `GIT_PROMPT_THEME` to the name +of the theme located in `/themes` without the extension `.bgptheme` like this: + +```sh +GIT_PROMPT_THEME=Solarized +``` + +If you set `GIT_PROMPT_THEME` to `Custom`, then the `.git-prompt-colors.sh` in the home directory will be used. +This file can now be generated with the command `git_prompt_make_custom_theme []`. If the name of +the base theme is ommitted or the theme file is not found, then the Default theme is used. If you have already a custom +`.git-prompt-colors.sh` in your home directory, a error message will be shown. + +You can display a list of available themes with `git_prompt_list_themes` (the current theme is highlighted) + +**If you omit the `GIT_PROMPT_THEME` variable, the Default theme is used or, if you have a custom `.git-prompt-colors.sh` +in your home directory, then the Custom theme is used.** + +#### Further customizations + - You can define `GIT_PROMPT_START` and `GIT_PROMPT_END` to tweak your prompt. - The default colors are defined within `prompt-colors.sh`, which is sourced by