Created
January 14, 2015 20:48
-
-
Save zsteinkamp/7960b27ac121f0ce6173 to your computer and use it in GitHub Desktop.
Bash Script to assemble a prompt that indicates user, host, directory, current branch, repo state.
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
| # Configure colors | |
| c_reset='\[\e[0m\]' | |
| c_user='\[\e[1;33m\]' | |
| c_path='\[\e[0;32m\]' | |
| c_git_clean='\[\e[0;36m\]' | |
| c_git_dirty='\[\e[0;31m\]' | |
| # Function to assemble the Git part of our prompt. | |
| git_prompt () | |
| { | |
| if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
| return 0 | |
| fi | |
| git_branch=$(git branch 2>/dev/null | sed -n '/^\*/s/^\* //p') | |
| if git diff --quiet 2>/dev/null >&2; then | |
| git_color="$c_git_clean" | |
| else | |
| git_color="$c_git_dirty" | |
| fi | |
| echo " $git_color$git_branch${c_reset}" | |
| } | |
| # The best prompt | |
| PROMPT_COMMAND='PS1="${c_user}\u@\H${c_reset} ${c_path}\w${c_reset}$(git_prompt) > "' | |
| ## | |
| # prompt | |
| if [ "$PS1" ]; then | |
| PS1='\[\e[0;33m\]\u@\h : \w>\[\e[0m\]' | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment