Skip to content

Commit

Permalink
GIT_PROMPT_SHOW_UNTRACKED_FILES=no was not working correctly
Browse files Browse the repository at this point in the history
* Fixed the bug, than GIT_SHOW_UNTRACKED_FILES=no was not respected
* Renamed GIT_SHOW_UNTRACKED_FILES to GIT_PROMPT_SHOW_UNTRACKED_FILES as
  this is more consistent to the other environment variables
* GIT_PROMPT_SHOW_UNTRACKED_FILES can be now also set on a per
  repository basis in .bash-git-rc
* Updated README

Fixes #215 and 216
  • Loading branch information
magicmonty committed Dec 24, 2015
1 parent 2d9ec22 commit 410fd05
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt
# GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status

# GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch
# GIT_SHOW_UNTRACKED_FILES=all # can be no, normal or all; determines counting of untracked files
# GIT_PROMPT_SHOW_UNTRACKED_FILES=all # can be no, normal or all; determines counting of untracked files

# 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
Expand All @@ -137,7 +137,7 @@ git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt
source ~/.bash-git-prompt/gitprompt.sh
```

You can set the `GIT_SHOW_UNTRACKED_FILES` variable to `no` or `normal` to speed things up if you have lots of
You can set the `GIT_PROMPT_SHOW_UNTRACKED_FILES` variable to `no` or `normal` to speed things up if you have lots of
untracked files in your repository. This can be the case for build systems that put their build artifacts in
the subdirectory structure of the git repository.

Expand Down Expand Up @@ -202,7 +202,7 @@ If you use a custom theme in `.git-prompt-colors.sh`, please set `GIT_PROMPT_THE
and end of the prompt by setting `GIT_PROMPT_START` and `GIT_PROMPT_END`
before you source the `gitprompt.sh`.

- The current git repo information is obtained by the script `gitstatus.sh`.
- The current git repo information is obtained by the script `gitstatus.sh`.
- You can define `prompt_callback` function to tweak your prompt dynamically.

```sh
Expand Down Expand Up @@ -247,6 +247,11 @@ GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 fo
- You can also ignore a repository completely by creating a file named ``.bash-git-rc`` with the
content ``GIT_PROMPT_IGNORE=1`` in the root of your git repository.

- If you have a repository with many untracked files, the git prompt can become very slow.
You can disable the display of untracked files on a per repository basis by setting
``GIT_PROMPT_SHOW_UNTRACKED_FILES=no`` in your ``.bash-git-rc`` in the repository or
by disabling it globally in your ``.bashrc``

- You can get help on the git prompt with the function ``git_prompt_help``.
Examples are available with ``git_prompt_examples``.
A list of all available named colors is available with `git_prompt_color_samples`
Expand Down
18 changes: 16 additions & 2 deletions gitprompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,18 @@ function setGitPrompt() {
fi

unset GIT_PROMPT_IGNORE
OLD_GIT_PROMPT_SHOW_UNTRACKED_FILES=${GIT_PROMPT_SHOW_UNTRACKED_FILES}
unset GIT_PROMPT_SHOW_UNTRACKED_FILES

if [[ -e "$repo/.bash-git-rc" ]]; then
source "$repo/.bash-git-rc"
fi

if [ -z "${GIT_PROMPT_SHOW_UNTRACKED_FILES}" ]; then
GIT_PROMPT_SHOW_UNTRACKED_FILES=${OLD_GIT_PROMPT_SHOW_UNTRACKED_FILES}
fi
unset OLD_GIT_PROMPT_SHOW_UNTRACKED_FILES

if [[ "$GIT_PROMPT_IGNORE" = 1 ]]; then
PS1="$EMPTY_PROMPT"
return
Expand Down Expand Up @@ -433,6 +440,12 @@ function updatePrompt() {
export __GIT_PROMPT_IGNORE_STASH=${GIT_PROMPT_IGNORE_STASH}
export __GIT_PROMPT_SHOW_UPSTREAM=${GIT_PROMPT_SHOW_UPSTREAM}

if [ -z "${GIT_PROMPT_SHOW_UNTRACKED_FILES}" ]; then
export __GIT_PROMPT_SHOW_UNTRACKED_FILES=all
else
export __GIT_PROMPT_SHOW_UNTRACKED_FILES=${GIT_PROMPT_SHOW_UNTRACKED_FILES}
fi

local -a git_status_fields
git_status_fields=($("$__GIT_STATUS_CMD" 2>/dev/null))

Expand Down Expand Up @@ -528,7 +541,8 @@ function gp_add_virtualenv_to_prompt {
function is_function {
declare -Ff "$1" >/dev/null;
}
#Helper function that truncates $PWD depending on window width

# Helper function that truncates $PWD depending on window width
function gp_truncate_pwd {
local tilde="~"
local newPWD="${PWD/#${HOME}/${tilde}}"
Expand All @@ -537,7 +551,7 @@ function gp_truncate_pwd {
echo -n "$newPWD"
}

#Sets the window title to the given argument string
# Sets the window title to the given argument string
function gp_set_window_title {
echo -ne "\033]0;"$@"\007"
}
Expand Down
6 changes: 1 addition & 5 deletions gitstatus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ if [ -z "${__GIT_PROMPT_DIR}" ]; then
__GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
fi

if [ -z "${GIT_SHOW_UNTRACKED_FILES}" ]; then
GIT_SHOW_UNTRACKED_FILES="all"
fi

gitstatus=$( LC_ALL=C git status --untracked-files=${GIT_SHOW_UNTRACKED_FILES} --porcelain --branch )
gitstatus=$( LC_ALL=C git status --untracked-files=${__GIT_PROMPT_SHOW_UNTRACKED_FILES} --porcelain --branch )

# if the status is fatal, exit now
[[ "$?" -ne 0 ]] && exit 0
Expand Down

0 comments on commit 410fd05

Please sign in to comment.