Created
April 15, 2022 21:27
-
-
Save ammarnajjar/76f743651d19ee8edb76b138ed6092d2 to your computer and use it in GitHub Desktop.
Custom prompt (left and right) for bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Author
ammarnajjar
commented
Apr 15, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment