Created
November 1, 2018 18:12
-
-
Save wrossmann/bd0fa6f76697406251119445e057acf4 to your computer and use it in GitHub Desktop.
Simple and full-featured bash prompt with git info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I've seen a _lot_ of code written to make bash prompts that are just _OK_, | |
# but there's no reason to invoke python/ruby/etc and parse git output since | |
# git ships with a pretty outstanding utility. | |
# 1. Load the library that already ships with git | |
source /usr/share/doc/${git_doc_path_here}/contrib/completion/git-prompt.sh | |
# 2. Set your options | |
export GIT_PS1_SHOWDIRTYSTATE=1 | |
export GIT_PS1_SHOWSTASHSTATE=1 | |
export GIT_PS1_SHOWCOLORHINTS=1 | |
export GIT_PS1_SHOWUNTRACKEDFILES=1 | |
# 3. Set the PROMPT_COMMAND | |
export PROMPT_COMMAND='__git_ps1 "\u@\h:\w" " \\\$ "' | |
# For more information just read `git-prompt.sh` and the other files in | |
# `doc/${git_doc_path_here}/contrib` as there's a lot of good info in there. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've found that this also unintentionally alters terminal titling if you don't preserve the portion of your previous PS1/PROMPT_COMMAND that is delimited by
\033]0;
and\007
which is the bit of data that sets your terminal title. Alsom now we need\[
and\]
to enclose non-printing prompt chars so that the terminal still renders correctly.So an updated step 3 would look like:
And also if you want full-colored goodness: