Last active
September 24, 2016 17:15
-
-
Save cbednarski/a0601388e3f4338519b2 to your computer and use it in GitHub Desktop.
Bash statusline
This file contains 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
# Color codes look like this: \033[1;34m | |
# | |
# When used in a prompt, color codes and other special sequences have to be | |
# escaped so they are not counted in the width of the bash prompt. If the width | |
# is not calculated correctly backspace, up arrow, etc. will not work correctly. | |
# | |
# In the bash prompt itself (PS1) you should use the \[ \] an escape sequence. | |
# This indicates to bash that these characters are not part of the prompt. | |
# | |
# If you're using color codes in a bash function that is used in your prompt, | |
# you instead need to use \001 and \002 to indicate the start and end of special | |
# codes, respectively. | |
# | |
# References: | |
# - http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html | |
# - http://mywiki.wooledge.org/BashFAQ/053 | |
function __cbednarski_ok { | |
if [ $? = 0 ]; then | |
printf "\001\033[1;34m\002$?\001\033[0m\002"; | |
else | |
printf "\001\033[1;31m\002$?\001\033[0m\002"; | |
fi | |
} | |
# Git Prompt | |
export GIT_PS1_SHOWDIRTYSTATE=1 | |
export PS1='\w\[\033[1;32m\]$(__git_ps1 " (%s)")\[\033[0m\] $(__cbednarski_ok)\$ ' | |
# Note you can get these via git clone https://github.com/git/git ~/code/git | |
. ~/code/git/contrib/completion/git-completion.bash | |
. ~/code/git/contrib/completion/git-prompt.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Last part i was doing git clone, so I ended with this: