From 5836a50cc15d3838865778c1933d95f0df8f2cb8 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Fri, 18 Apr 2014 20:51:44 +0200 Subject: [PATCH] Made the start and end of the prompt configurable via the .git-prompt-colors.sh --- README.md | 18 ++++++++++++------ git-prompt-colors.sh | 41 +++++++++++++++++++++++++---------------- gitprompt.sh | 28 +++++++++++++++++----------- 3 files changed, 54 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 6c899e8..32e3035 100644 --- a/README.md +++ b/README.md @@ -51,18 +51,24 @@ The symbols are as follows: 1. Clone this repository to your homedir e.g. ``git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt`` -2. Source the file ``gitprompt.sh`` from your ``~/.bashrc`` config file +2. Source the file ``gitprompt.sh`` from your ``~/.bashrc`` config file: + ```bash + # some other config in .bashrc + + # gitprompt configuration + source .bash-git-prompt/gitprompt.sh + ``` 3. Go in a git repository and test it! ## Configuration -1. You can use ``GIT_PROMPT_START`` and ``GIT_PROMPT_END`` to tweak your prompt - -2. The default colors are defined within ``gitprompt.sh``, but may be - overridden by copying ``git-prompt-colors.sh`` to your home directory at - ``~/.git-prompt-colors.sh``. This file may also be found in the same +1. The default colors and some variables for tweaking the prompt are defined + within ``gitprompt.sh``, but may be overridden by copying ``git-prompt-colors.sh`` + to your home directory at ``~/.git-prompt-colors.sh``. This file may also be found in the same directory as ``gitprompt.sh``, but without the leading ``.``. +2. You can use ``GIT_PROMPT_START_USER``, ``GIT_PROMPT_START_ROOT``, ``GIT_PROMPT_END_USER`` and ``GIT_PROMPT_END_ROOT`` in your ``.git-prompt-colors.sh`` to tweak your prompt. You can also override the start and end of the prompt by setting ``GIT_PROMPT_START`` and ``GIT_PROMPT_END`` before you source the ``gitprompt.sh`` + 3. The current git repo information is obtained by the script `gitstatus.sh` or `gitstatus.py`. Both scripts do the same thing, but the bash script is a tad more quick, and is used by default. If you prefer the python script diff --git a/git-prompt-colors.sh b/git-prompt-colors.sh index 1e8c423..355811c 100644 --- a/git-prompt-colors.sh +++ b/git-prompt-colors.sh @@ -1,18 +1,27 @@ - # 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 +local Time12a="\$(date +%H:%M)" +local PathShort="\w" - 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 +# 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 - # Please do not add colors to these symbols - GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" - GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" - GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found +GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory +GIT_PROMPT_STAGED="${Red}●" # the number of staged files/directories +GIT_PROMPT_CONFLICTS="${Red}✖" # the number of files in conflict +GIT_PROMPT_CHANGED="${Blue}✚" # the number of changed files + +GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind +GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs +GIT_PROMPT_STASHED="${BoldBlue}⚑" # the number of stashed files/dir +GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo + +GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" +GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}" +GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " +GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + +# Please do not add colors to these symbols +GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" +GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" +GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found \ No newline at end of file diff --git a/gitprompt.sh b/gitprompt.sh index 96e8e77..e6017be 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -63,6 +63,13 @@ function git_prompt_config() done done fi + + # Various variables you might want for your PS1 prompt instead + local Time12a="\$(date +%H:%M)" + # local Time12a="(\$(date +%H:%M:%S))" + # local Time12a="(\@))" + local PathShort="\w" + # if the envar is defined, source the file for custom colors if [[ -n "$__GIT_PROMPT_COLORS_FILE" && -f "$__GIT_PROMPT_COLORS_FILE" ]]; then source "$__GIT_PROMPT_COLORS_FILE" @@ -82,24 +89,23 @@ function git_prompt_config() GIT_PROMPT_STASHED="${BoldBlue}⚑" GIT_PROMPT_CLEAN="${BoldGreen}✔" + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + # Please do not add colors to these symbols GIT_PROMPT_SYMBOLS_AHEAD="↑·" GIT_PROMPT_SYMBOLS_BEHIND="↓·" GIT_PROMPT_SYMBOLS_PREHASH=":" fi - # Various variables you might want for your PS1 prompt instead - local Time12a="\$(date +%H:%M)" - # local Time12a="(\$(date +%H:%M:%S))" - # local Time12a="(\@))" - local PathShort="\w" - if [ "x${GIT_PROMPT_START}" == "x" ]; then #First statment is for non root behavior second for root - if ! $_isroot; then - PROMPT_START="${Yellow}${PathShort}${ResetColor}" + if $_isroot; then + PROMPT_START="${GIT_PROMPT_START_ROOT}" else - PROMPT_START="${Yellow}${PathShort}${ResetColor}" + PROMPT_START="${GIT_PROMPT_START_USER}" fi else PROMPT_START="${GIT_PROMPT_START}" @@ -108,9 +114,9 @@ function git_prompt_config() if [ "x${GIT_PROMPT_END}" == "x" ]; then #First statment is for non root behavior second for root if ! $_isroot; then - PROMPT_END=" \n${White}${Time12a}${ResetColor} $ " + PROMPT_END="${GIT_PROMPT_END_USER}" else - PROMPT_END=" \n${White}${Time12a}${ResetColor} # " + PROMPT_END="${GIT_PROMPT_END_ROOT}" fi else PROMPT_END="${GIT_PROMPT_END}"