dotfiles/.functions/ps1.sh

39 lines
1.5 KiB
Bash
Raw Normal View History

2021-11-11 15:27:24 +00:00
#!/bin/bash
function set_bash_prompt () {
local LAST_EXIT_STATUS=$?
local EXIT_STATUS=""
local Color_Off='\033[0m' # Text Reset
local COLOR_DIVIDER="\033[0;32m"
local COLOR_USERNAME="\[\e[34;1m\]"
local COLOR_USERHOSTAT="\[\e[34;1m\]"
local COLOR_HOSTNAME="\[\e[34;1m\]"
local COLOR_GITBRANCH="\[\e[33;1m\]"
local COLOR_VENV="\033[0;36m"
local PATH_COLOR="\033[0;37m"
if [[ $LAST_EXIT_STATUS != 0 ]];then
2021-11-11 15:29:02 +00:00
EXIT_STATUS="${COLOR_DIVIDER}[\033[1;37m\033[41m${LAST_EXIT_STATUS}${Color_Off}${COLOR_DIVIDER}]"
2021-11-11 15:27:24 +00:00
fi
PS1="\n${COLOR_DIVIDER}┌──(${COLOR_USERNAME}\u${COLOR_USERHOSTAT}@${COLOR_HOSTNAME}\h${COLOR_DIVIDER})─[${PATH_COLOR}\w${COLOR_DIVIDER}]${EXIT_STATUS}"
PS1="$PS1${COLOR_GITBRANCH}$(__git_ps1)${COLOR_DIVIDER}"
# # Add git branch portion of the prompt"
# if ! git_loc="$(type -p "$git_command_name")" || [ -z "$git_loc" ]; then
# # Git is installed
# if [ -d .git ] || git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
# # Inside of a git repository
# GIT_BRANCH=$(git symbolic-ref --short HEAD)
# PS1="${PS1}:${COLOR_GITBRANCH}${GIT_BRANCH}${COLOR_DIVIDER}"
# fi
# fi
# Add Python VirtualEnv portion of the prompt, this adds ":venvname"
if ! test -z "$VIRTUAL_ENV" ; then
PS1="${PS1}(${COLOR_VENV}${VIRTUAL_ENV##*/}${COLOR_DIVIDER})"
fi
PS1="${PS1}\n${COLOR_DIVIDER}└─\$${Color_Off} "
}
# Tell Bash to run the above function for every prompt
export PROMPT_COMMAND=set_bash_prompt