Last active
November 6, 2019 14:45
-
-
Save fragmuffin/254be496927a1ec31ef7b335291f9865 to your computer and use it in GitHub Desktop.
Bash command prompt PS1
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
#... portion of .bashrc | |
export GIT_PS1_SHOWDIRTYSTATE=true # staged '+', unstaged '*' | |
export GIT_PS1_SHOWUNTRACKEDFILES=true # '%' untracked files | |
export GIT_PS1_SHOWUPSTREAM="auto" # '<' behind, '>' ahead, '<>' diverged, '=' no difference | |
export GIT_PS1_SHOWSTASHSTATE=true # '$' something is stashed | |
function __prompt_command() { | |
local ERRORCODE="$?" | |
# colour codes | |
local c_grey="\[\e[90m\]" | |
local c_red="\[\e[1;31m\]" | |
local c_green="\[\e[32m\]" | |
local c_yellow="\[\e[33;1m\]" | |
local c_clear="\[\e[0m\]" | |
PS1="${debian_chroot:+($debian_chroot)}" | |
# Errorcode (conditional) | |
if [ ${ERRORCODE} != 0 ]; then | |
PS1+="${c_grey} $(echo -e '\u2570\u2500\u2770')${c_red}${ERRORCODE}${c_grey}$(echo -e '\u2771')${c_clear}\n" | |
fi | |
# Main line | |
local pre_line="$(echo -e '\u256d\u2500')" | |
if [[ "$(dirs -p | wc -l)" != "1" ]] ; then | |
local pre_line="$(echo -e '\u2934') " | |
fi | |
PS1+="${c_grey}${pre_line}${c_clear}" | |
if [[ ! -z "${VIRTUAL_ENV}" ]]; then | |
PS1+="${c_grey}$(echo -e '\u2770')${c_green}$(basename $VIRTUAL_ENV)${c_grey}$(echo -e '\u2771')${c_clear}" | |
fi | |
PS1+=" ${c_yellow}\w${c_clear}" | |
PS1+="\$(__git_ps1)" | |
# Command Line | |
PS1+="\n${c_grey}$(echo -e '\u2570\u2500\u2bc8') ${c_clear}" | |
} | |
export PROMPT_COMMAND=__prompt_command | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment