From 410fd059a7f092d9e45633411b356769975be574 Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Thu, 24 Dec 2015 14:21:26 +0100 Subject: [PATCH] GIT_PROMPT_SHOW_UNTRACKED_FILES=no was not working correctly * 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 --- README.md | 13 +++++++++---- gitprompt.sh | 18 ++++++++++++++++-- gitstatus.sh | 6 +----- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fd2fe292..e2f0d475 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. @@ -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 @@ -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` diff --git a/gitprompt.sh b/gitprompt.sh index fe305aa9..d679acde 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -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 @@ -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)) @@ -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}}" @@ -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" } diff --git a/gitstatus.sh b/gitstatus.sh index 4bf276a8..0e373109 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -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