Skip to content

Git wrapper script for writing information to be displayed in a bash prompt

Notifications You must be signed in to change notification settings

chrisejones/cached-git-prompt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

cached-git-prompt

Git wrapper script for writing information to be displayed in a Bash prompt

Introduction

Many custom Bash prompts shell out to Git to populate information about the Git repository in the current working directory, but in some environments shelling out to external commands is relatively slow and makes the prompt feel laggy.

This project takes an alternative approach. We wrap Git in a script that works out the repository directory of the executed command and caches information to be rendered in the prompt.

Usage

Minimal example to add to your .bashrc

CACHED_GIT_INFO_DIRECTORY="$HOME/git/cached-git-prompt"

source "$CACHED_GIT_INFO_DIRECTORY/cached_git_prompt.bash"
alias git="$CACHED_GIT_INFO_DIRECTORY/git-prompt-info-wrapper"

ORIG_PS1=$PS1

# Prepend git info to your existing prompt
ps1() {
  git_info=$(cached_git_info)
  if [[ -z $git_info ]]; then
    PS1="$ORIG_PS1"
  else
    PS1="$git_info $ORIG_PS1"
  fi
}

PROMPT_COMMAND="ps1${PROMPT_COMMAND:+; $PROMPT_COMMAND}"

We recommend that you add the file that's used to cache Git information to a global Git ignore list.

echo ".prompt_git_info.txt" > ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global

Using the Official Git Prompt

By default we use a simple implementation. To use the official Git prompt, or a custom one:

export CACHED_GIT_INFO_FULL=true

If git-prompt.sh is not in /usr/local/etc/bash_completion.d/git-prompt.sh or /etc/bash_completion.d/git-prompt.sh then set CACHED_GIT_INFO_GIT_PROMPT_PATH to its location.

About

Git wrapper script for writing information to be displayed in a bash prompt

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages