Last active
December 20, 2015 21:39
-
-
Save tonywok/6198912 to your computer and use it in GitHub Desktop.
Simple little bash script for a decent bash prompt
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
| if [ -f `brew --prefix`/etc/bash_completion ]; then | |
| . `brew --prefix`/etc/bash_completion | |
| fi | |
| GREEN="\033[0;32m" | |
| CYAN="\033[0;36m" | |
| BLUE="\033[0;34m" | |
| RED="\033[0;31m" | |
| RESET="\033[0m" | |
| function git-prompt { | |
| local prompt="" | |
| if [[ -d "./.git" ]]; then | |
| prompt="$prompt$(__git_ps1 '(%s)')" | |
| if test -n "$(git status --porcelain)"; then | |
| local status="$(git status --porcelain | cut -c 1-2 | uniq)" | |
| if [[ $status =~ (A )|(D )|(R )|(M ) ]]; then # staged | |
| prompt="$prompt$CYAN ✔" | |
| fi | |
| if [[ $status =~ ( M) ]]; then # modified | |
| prompt="$prompt$GREEN ●" | |
| fi | |
| if [[ $status =~ (\?\?) ]]; then # untracked | |
| prompt="$prompt$BLUE ●" | |
| fi | |
| if [[ $status =~ (U )|( U) ]]; then # conflict | |
| prompt="$prompt$RED x" | |
| fi | |
| else | |
| prompt="$prompt ✔" | |
| fi | |
| fi | |
| echo -e "$prompt" | |
| } | |
| export PS1="${CYAN}\u@\h: ${RESET}\W ${GREEN}\$(git-prompt) ${RESET} \n→ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment