Skip to content

Instantly share code, notes, and snippets.

@ricardobeat
Created July 12, 2013 02:04
Show Gist options
  • Save ricardobeat/5980892 to your computer and use it in GitHub Desktop.
Save ricardobeat/5980892 to your computer and use it in GitHub Desktop.
Powerline-style bash prompt
_ps1_clear() {
echo -n "\e[0m"
}
_ps1_fg() {
echo -n "\e[38;5;$1m"
}
_ps1_bg() {
echo -n "\e[48;5;$1m"
}
_ps1_jobs() {
if [ `jobs | wc -l` -gt 0 ]; then
echo -n "$(_ps1_fg 229)\j⃣"
fi
}
_ps1_star() {
echo -n "$(_ps1_fg $(($RANDOM % 255)))✭"
}
_parse_git_branch() {
if [[ `git status 2> /dev/null` == *nothing\ to\ commit* ]]; then _ps1_fg 99; else _ps1_fg 32; fi
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
_update_ps1() {
local parts=(
"\n$(_ps1_clear)$(_ps1_bg 236)$(_ps1_fg 236)"
"$(_ps1_fg 246)\w"
"$(_parse_git_branch)"
"$(_ps1_clear)$(_ps1_fg 236) $(_ps1_jobs)"
"\n$(_ps1_star) $(_ps1_clear)"
)
export PS1="${parts[@]}"
}
export PROMPT_COMMAND="_update_ps1"
@jcemer
Copy link

jcemer commented Jul 12, 2013

Cool. But mine is best! https://github.com/jcemer/dotfiles-mac

@ricardobeat
Copy link
Author

ricardobeat commented Jul 12, 2013

@jcemer not as pretty and doesn't show job count :P

The asterisk is a nice touch, might work better than just switching colors.

I'm using 256 colors btw, see here http://misc.flogisoft.com/bash/tip_colors_and_formatting#background1

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