Skip to content

Instantly share code, notes, and snippets.

@ammarnajjar
Created April 15, 2022 21:27
Show Gist options
  • Save ammarnajjar/76f743651d19ee8edb76b138ed6092d2 to your computer and use it in GitHub Desktop.
Save ammarnajjar/76f743651d19ee8edb76b138ed6092d2 to your computer and use it in GitHub Desktop.
Custom prompt (left and right) for bash
RED='\033[0;31m'
YELLOW='\033[0;33m'
LIGHT_GREEN='\033[0;32m'
LIGHT_GRAY='\033[0;37m'
NORMAL='\033[0m'
function prompt_right() {
echo -e "${LIGHT_GRAY}\\\t${NORMAL}"
}
function prompt_left() {
GIT_BRANCH=""
BRANCH=$(git branch 2>/dev/null | grep '^*' | sed s/..//)
if [ ! -z "$BRANCH" ]; then GIT_BRANCH=" [${LIGHT_GREEN}${BRANCH}${NORMAL}]"; fi
echo -e "${YELLOW}\w${NORMAL}${GIT_BRANCH}"
}
function prompt_command() {
compensate=4
PS1=$(printf "%*s\r%s\n\$ " "$(($(tput cols)+${compensate}))" "$(prompt_right)" "$(prompt_left)")
}
PROMPT_COMMAND=prompt_command
@ammarnajjar
Copy link
Author

image

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