Skip to content

Instantly share code, notes, and snippets.

@amsnickw
Last active March 15, 2023 02:41
Show Gist options
  • Save amsnickw/da2031f284e58b497e38b1a514452d79 to your computer and use it in GitHub Desktop.
Save amsnickw/da2031f284e58b497e38b1a514452d79 to your computer and use it in GitHub Desktop.
Lightweight git prompt for ksh93 (real, AT&T version of the Korn shell).
# Simple, lightweight git prompt for ksh93: if inside a git repo, adds the
# branch name to PS1, using a different color for master, develop* and other.
# Put this snippet at the bottom of your ~/.kshrc
__get_current_git_branch_name() {
__determine_branch_color() {
case "${1:-}" in
master) branch_color=196 ;; # red
develop*) branch_color=226 ;; # yellow
*) branch_color=39 # blue
esac
echo -n "$branch_color"
}
branch_name="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)" && \
[ -n "$branch_name" ] && \
use_branch_color="$(__determine_branch_color "$branch_name")" && \
branch_name="$(printf "\e[38;5;%dm (%s)\e[0m" $use_branch_color $branch_name)"
echo -en "$branch_name"
}
thishost=$(hostname)
export PS1='${LOGNAME}@${thishost}:${PWD/${HOME}/\~}$(__get_current_git_branch_name)$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment