Skip to content

Instantly share code, notes, and snippets.

@cbednarski
Last active September 24, 2016 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbednarski/a0601388e3f4338519b2 to your computer and use it in GitHub Desktop.
Save cbednarski/a0601388e3f4338519b2 to your computer and use it in GitHub Desktop.
Bash statusline
# 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
@kikitux
Copy link

kikitux commented Sep 24, 2016

Last part i was doing git clone, so I ended with this:


for file in git-completion.bash git-prompt.sh; do
   [ -f ${code}/${file} ] || curl -sSL https://raw.githubusercontent.com/git/git/master/contrib/completion/${file} -o ${code}/${file}
done

source ${code}/git-completion.bash
source ${code}/git-prompt.sh

@cbednarski
Copy link
Author

Ah great idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment