Merge branch 'master' of https://github.com/aks/bash-git-prompt into aks-master

master
unknown 12 years ago
commit b9855cd627
  1. 25
      README.md
  2. 13
      git-prompt-colors.sh
  3. 56
      git-prompt-help.sh
  4. 34
      gitprompt.sh
  5. 2
      gitstatus.sh

@ -1,9 +1,11 @@
# Informative git prompt for bash and fish # Informative git prompt for bash and fish
This prompt is a port of the "Informative git prompt for zsh" which you can find [here](https://github.com/olivierverdier/zsh-git-prompt) This prompt is a port of the "Informative git prompt for zsh" which you can
find [here](https://github.com/olivierverdier/zsh-git-prompt)
A ``bash`` prompt that displays information about the current git repository. 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. In particular the branch name, difference with remote branch, number of files
staged, changed, etc.
(an original idea from this [blog post][]). (an original idea from this [blog post][]).
@ -55,13 +57,19 @@ The symbols are as follows:
## Configuration ## Configuration
1. You can use ``GIT_PROMPT_START`` and ``GIT_PROMPT_END`` to tweak your prompt 1. You can use ``GIT_PROMPT_START`` and ``GIT_PROMPT_END`` to tweak your prompt
2. If you want to tweak the colors, currently you have to tweak it in the
``gitprompt.sh``. See the definitions of ``GIT_PROMPT_xxx1``, which include 2. The default colors are defined within ``gitprompt.sh``, but may be
various colors names. 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 ``.``.
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 bit more quick, and is used by default. tad more quick, and is used by default. If you prefer the python script
4. You can define ``prompt_callback`` function to tweak your prompt dynamicaly (possibly because you have enhanced it), simply delete or change the name of
``gitstatus.sh``.
4. You can define ``prompt_callback`` function to tweak your prompt dynamically.
```sh ```sh
function prompt_callback { function prompt_callback {
@ -71,6 +79,9 @@ function prompt_callback {
} }
``` ```
5. You can get help on the git prompt with the function ``git_prompt_help``.
Examples are available with ``git_prompt_examples``.
**Enjoy!** **Enjoy!**
[blog post]: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ [blog post]: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/

@ -0,0 +1,13 @@
# 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)
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

@ -0,0 +1,56 @@
#!/bin/bash
# git-prompt-help -- show useful info to help new users with the information
# being displayed.
git_prompt_help() {
cat <<EOF 1>&2
The git prompt format is [<BRANCH><TRACKING>|<LOCALSTATUS>]
BRANCH is a branch name, such as "master" or "stage", a tag name, or commit
hash prefixed with ':'.
TRACKING indicates how the local branch differs from the
remote branch. It can be empty, or one of:
↑N - ahead of remote by N commits
↓N - behind remote by N commits
↓M↑N - branches diverged, other by M commits, yours by N commits
LOCALSTATUS is one of the following:
✔ - repository clean
●N - N staged files
✖N - N unmerged files
✚N - N changed but *unstaged* files
…N - N untracked files
⚑N - N stash entries
See "git_prompt_examples" for examples.
EOF
}
help_git_prompt() { git_prompt_help ; }
git_prompt_examples() {
cat <<EOF 1>&2
These are examples of the git prompt:
(master↑3|✚1) - on branch "master", ahead of remote by 3 commits, 1
file changed but not staged
(status|●2) - on branch "status", 2 files staged
(master|✚7…) - on branch "master", 7 files changed, some files untracked
(master|✖2✚3) - on branch "master", 2 conflicts, 3 files changed
(master|⚑2) - on branch "master", 2 stash entries
(experimental↓2↑3|) - on branch "experimental"; your branch has diverged
by 3 commits, remote by 2 commits; the repository is
otherwise clean
(:70c2952|) - not on any branch; parent commit has hash "70c2952"; the
repository is otherwise clean
EOF
}

@ -44,18 +44,40 @@ function git_prompt_config()
local Blue="\[\033[0;34m\]" local Blue="\[\033[0;34m\]"
local Cyan="\[\033[0;36m\]" local Cyan="\[\033[0;36m\]"
# Default values for the appearance of the prompt. Configure at will. # source the user's ~/.git-prompt-colors.sh file, or the one that should be
# sitting in the same directory as this script
if [[ -z "$__GIT_PROMPT_COLORS_FILE" ]]; then
local pfx file dir
for dir in "$HOME" "$__GIT_PROMPT_DIR" ; do
for pfx in '.' '' ; do
file="$dir/${pfx}git-prompt-colors.sh"
if [[ -f "$file" ]]; then
__GIT_PROMPT_COLORS_FILE="$file"
break 2
fi
done
done
fi
# 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"
else
# Default values for the appearance of the prompt. Do not change these
# below. Instead, copy these to `~/.git-prompt-colors.sh` and change them
# there.
GIT_PROMPT_PREFIX="[" GIT_PROMPT_PREFIX="["
GIT_PROMPT_SUFFIX="]" GIT_PROMPT_SUFFIX="]"
GIT_PROMPT_SEPARATOR="|" GIT_PROMPT_SEPARATOR="|"
GIT_PROMPT_BRANCH="${Magenta}" GIT_PROMPT_BRANCH="${Magenta}"
GIT_PROMPT_STAGED="${Red}" GIT_PROMPT_STAGED="${Red}"
GIT_PROMPT_CONFLICTS="${Red}" GIT_PROMPT_CONFLICTS="${Red}"
GIT_PROMPT_CHANGED="${Blue}" GIT_PROMPT_CHANGED="${Blue}"
GIT_PROMPT_REMOTE=" " GIT_PROMPT_REMOTE=" "
GIT_PROMPT_UNTRACKED="${Cyan}" GIT_PROMPT_UNTRACKED="${Cyan}"
GIT_PROMPT_STASHED="${BoldBlue}" GIT_PROMPT_STASHED="${BoldBlue}"
GIT_PROMPT_CLEAN="${BoldGreen}" GIT_PROMPT_CLEAN="${BoldGreen}"
fi
# Various variables you might want for your PS1 prompt instead # Various variables you might want for your PS1 prompt instead
local Time12a="\$(date +%H:%M)" local Time12a="\$(date +%H:%M)"
@ -91,8 +113,6 @@ function git_prompt_config()
break break
fi fi
done done
# The old way
#__GIT_STATUS_CMD="${__GIT_PROMPT_DIR}/gitstatus.py"
fi fi
} }

@ -1,4 +1,4 @@
#/bin/bash #!/bin/bash
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# gitstatus.sh -- produce the current git repo status on STDOUT # gitstatus.sh -- produce the current git repo status on STDOUT
# Functionally equivalent to 'gitstatus.py', but written in bash (not python). # Functionally equivalent to 'gitstatus.py', but written in bash (not python).

Loading…
Cancel
Save