Made the start and end of the prompt configurable via the .git-prompt-colors.sh

master
Martin Gondermann 12 years ago
parent 08212d8a92
commit 5836a50cc1
  1. 18
      README.md
  2. 41
      git-prompt-colors.sh
  3. 28
      gitprompt.sh

@ -51,18 +51,24 @@ The symbols are as follows:
1. Clone this repository to your homedir 1. Clone this repository to your homedir
e.g. ``git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt`` 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! 3. Go in a git repository and test it!
## Configuration ## Configuration
1. You can use ``GIT_PROMPT_START`` and ``GIT_PROMPT_END`` to tweak your prompt 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``
2. The default colors are defined within ``gitprompt.sh``, but may be to your home directory at ``~/.git-prompt-colors.sh``. This file may also be found in the same
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 ``.``. 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 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 `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 tad more quick, and is used by default. If you prefer the python script

@ -1,18 +1,27 @@
# These are the color definitions used by gitprompt.sh local Time12a="\$(date +%H:%M)"
GIT_PROMPT_PREFIX="[" # start of the git info string local PathShort="\w"
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 # These are the color definitions used by gitprompt.sh
GIT_PROMPT_STAGED="${Red}" # the number of staged files/directories GIT_PROMPT_PREFIX="[" # start of the git info string
GIT_PROMPT_CONFLICTS="${Red}" # the number of files in conflict GIT_PROMPT_SUFFIX="]" # the end of the git info string
GIT_PROMPT_CHANGED="${Blue}" # the number of changed files GIT_PROMPT_SEPARATOR="|" # separates each item
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
# Please do not add colors to these symbols GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory
GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" GIT_PROMPT_STAGED="${Red}" # the number of staged files/directories
GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" GIT_PROMPT_CONFLICTS="${Red}" # the number of files in conflict
GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found 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

@ -63,6 +63,13 @@ function git_prompt_config()
done done
done done
fi fi
# Various variables you might want for your PS1 prompt instead
local Time12a="\$(date +%H:%M)"
# local Time12a="(\$(date +%H:%M:%S))"
# local Time12a="(\@))"
local PathShort="\w"
# if the envar is defined, source the file for custom colors # if the envar is defined, source the file for custom colors
if [[ -n "$__GIT_PROMPT_COLORS_FILE" && -f "$__GIT_PROMPT_COLORS_FILE" ]]; then if [[ -n "$__GIT_PROMPT_COLORS_FILE" && -f "$__GIT_PROMPT_COLORS_FILE" ]]; then
source "$__GIT_PROMPT_COLORS_FILE" source "$__GIT_PROMPT_COLORS_FILE"
@ -82,24 +89,23 @@ function git_prompt_config()
GIT_PROMPT_STASHED="${BoldBlue}" GIT_PROMPT_STASHED="${BoldBlue}"
GIT_PROMPT_CLEAN="${BoldGreen}" 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 # Please do not add colors to these symbols
GIT_PROMPT_SYMBOLS_AHEAD="↑·" GIT_PROMPT_SYMBOLS_AHEAD="↑·"
GIT_PROMPT_SYMBOLS_BEHIND="↓·" GIT_PROMPT_SYMBOLS_BEHIND="↓·"
GIT_PROMPT_SYMBOLS_PREHASH=":" GIT_PROMPT_SYMBOLS_PREHASH=":"
fi fi
# Various variables you might want for your PS1 prompt instead
local Time12a="\$(date +%H:%M)"
# local Time12a="(\$(date +%H:%M:%S))"
# local Time12a="(\@))"
local PathShort="\w"
if [ "x${GIT_PROMPT_START}" == "x" ]; then if [ "x${GIT_PROMPT_START}" == "x" ]; then
#First statment is for non root behavior second for root #First statment is for non root behavior second for root
if ! $_isroot; then if $_isroot; then
PROMPT_START="${Yellow}${PathShort}${ResetColor}" PROMPT_START="${GIT_PROMPT_START_ROOT}"
else else
PROMPT_START="${Yellow}${PathShort}${ResetColor}" PROMPT_START="${GIT_PROMPT_START_USER}"
fi fi
else else
PROMPT_START="${GIT_PROMPT_START}" PROMPT_START="${GIT_PROMPT_START}"
@ -108,9 +114,9 @@ function git_prompt_config()
if [ "x${GIT_PROMPT_END}" == "x" ]; then if [ "x${GIT_PROMPT_END}" == "x" ]; then
#First statment is for non root behavior second for root #First statment is for non root behavior second for root
if ! $_isroot; then if ! $_isroot; then
PROMPT_END=" \n${White}${Time12a}${ResetColor} $ " PROMPT_END="${GIT_PROMPT_END_USER}"
else else
PROMPT_END=" \n${White}${Time12a}${ResetColor} # " PROMPT_END="${GIT_PROMPT_END_ROOT}"
fi fi
else else
PROMPT_END="${GIT_PROMPT_END}" PROMPT_END="${GIT_PROMPT_END}"

Loading…
Cancel
Save