Skip to content

Instantly share code, notes, and snippets.

@grenade
Last active August 24, 2021 08:40
Show Gist options
  • Select an option

  • Save grenade/fbb22fbb774ce3df8add to your computer and use it in GitHub Desktop.

Select an option

Save grenade/fbb22fbb774ce3df8add to your computer and use it in GitHub Desktop.
My PS1 implementation, documented
# ...
# User specific aliases and functions
export VCP_PREFIX="{ "
export VCP_NAME="{symbol}" # You can use "value" or "symbol" here
export VCP_BRANCH="{blue}{value}{reset}"
export VCP_OPERATION="{red}{value}{reset}"
export VCP_BEHIND="↓{value}"
export VCP_AHEAD="↑{value}"
export VCP_SEPARATOR="|"
export VCP_STAGED="{blue}✚{value}" # +
export VCP_CONFLICT="{red}✖︎{value}" # ×
export VCP_CHANGED="{yellow}↻{value}" #
export VCP_UNTRACKED="{magenta}…{value}"
export VCP_CLEAN="{green}✔︎" # ✓
export VCP_SUFFIX="{reset} }"
export PS1='[\u@\h:\w $(vcprompt)] \$ '

more better ps1

Take a little time to make yourself a better PS1 experience in bash. There are lots of PS1 variations out in the wild, but I wanted something:

  • Fast. All the Python implementations slow bash to a crawl. That's terrible. Bash should be fast.
  • Broad. Most PS1 implementations cater for one or maybe two VCS variants. I use them all. I need something that works for them all.
  • Useful. I need to see at least the branch, current revison and mod state. I'd prefer to also get some counts (unstaged, modded, deleted, etc).
  • Colourful. Almost everybody wants this. And everybody can have it. You just have to be methodical when escaping your colour change drectives. Eg: you can get a pale blue with $(tput setaf 153), but you should wrap it like this: \[$(tput setaf 153)\] to avoid early line wraps in the terminal window. Use this colour chart to pick colors that work for you.

VCPrompt is the best I have found so far. It's lightweight and blazingly fast, because it's written in c. It's open source too, so if I ever pull my thumb out, I could implement the counts I want.

update 2021-08-24

there is still a chaotic assortment of vcprompt and ps1 implementations on the wild-wild-web but rust-vcprompt outshines them all. no need to mess around with anything else.

cargo install --root=$HOME/.local vcprompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment