Last active
March 12, 2020 10:49
-
-
Save ebassi/818bf58c0a42763d8ad0c0d46cf1f2b4 to your computer and use it in GitHub Desktop.
Fancy pants PS1
This file contains 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
# .bashrc | |
# Source global definitions | |
if [ -f /etc/bashrc ]; then | |
. /etc/bashrc | |
fi | |
export EDITOR=vim | |
export PAGER=less | |
source /usr/share/git-core/contrib/completion/git-prompt.sh | |
GIT_PS1_SHOWDIRTYSTATE=1 | |
GIT_PS1_SHOWUNTRACKEDFILES=1 | |
GIT_PS1_BLACKLIST='WebKit llvm gcc gecko-dev servo rust' | |
# pretty hacky wrapper around __git_ps1 that checks directories in a blacklist | |
__git_maybe_ps1() | |
{ | |
local fmt='' | |
if [ -z "${1-}" ]; then | |
fmt='(%s)' | |
else | |
fmt=${1} | |
fi | |
local cur_dir=$( pwd ) | |
local print_ps1='yes' | |
for black in ${GIT_PS1_BLACKLIST}; do | |
if [[ "${cur_dir}" == *${black}* ]]; then | |
print_ps1='no' | |
break; | |
fi | |
done | |
if [ $print_ps1 == 'yes' ]; then | |
echo $(__git_ps1 "$fmt") | |
fi | |
} | |
__toolbox_maybe_ps1() | |
{ | |
if [ -f "/run/.containerenv" ]; then | |
echo "📦" | |
fi | |
} | |
__jhbuild_maybe_ps1() | |
{ | |
if [ -n "$UNDER_JHBUILD" ]; then | |
echo "👣" | |
fi | |
} | |
generate_prompt() | |
{ | |
local NO_FORMAT="\e[0m" | |
## Effect | |
local NONE='0' | |
local BOLD='1' | |
local DIM='2' | |
local UNDERLINE='4' | |
local BLINK='5' | |
local INVERT='7' | |
local HIDDEN='8' | |
## Foreground color | |
local FG_DEFAULT='39' | |
local FG_BLACK='30' | |
local FG_RED='31' | |
local FG_GREEN='32' | |
local FG_YELLOW='33' | |
local FG_BLUE='34' | |
local FG_MAGENTA='35' | |
local FG_CYAN='36' | |
local FG_LIGHT_GRAY='37' | |
local FG_DARK_GRAY='90' | |
local FG_LIGHT_RED='91' | |
local FG_LIGHT_GREEN='92' | |
local FG_LIGHT_YELLOW='93' | |
local FG_LIGHT_BLUE='94' | |
local FG_LIGHT_MAGENTA='95' | |
local FG_LIGHT_CYAN='96' | |
local FG_WHITE='97' | |
## Background color | |
local BG_DEFAULT='49' | |
local BG_BLACK='40' | |
local BG_RED='41' | |
local BG_GREEN='42' | |
local BG_YELLOW='43' | |
local BG_BLUE='44' | |
local BG_MAGENTA='45' | |
local BG_CYAN='46' | |
local BG_LIGHT_GRAY='47' | |
local BG_DARK_GRAY='100' | |
local BG_LIGHT_RED='101' | |
local BG_LIGHT_GREEN='102' | |
local BG_LIGHT_YELLOW='103' | |
local BG_LIGHT_BLUE='104' | |
local BG_LIGHT_MAGENTA='105' | |
local BG_LIGHT_CYAN='106' | |
local BG_WHITE='107' | |
# Text | |
local TEXT_FORMAT_1="\e[${BOLD};${FG_WHITE};${BG_DARK_GRAY}m" | |
local TEXT_FORMAT_2="\e[${BOLD};${FG_WHITE};${BG_LIGHT_BLUE}m" | |
local TEXT_FORMAT_3="\e[${DIM};${FG_DARK_GRAY};${BG_WHITE}m" | |
# Separator; FG=BG previous section, BG=BG next section | |
local SEPARATOR_FORMAT_1="\e[${FG_DARK_GRAY};${BG_LIGHT_BLUE}m" | |
local SEPARATOR_FORMAT_2="\e[${FG_LIGHT_BLUE};${BG_WHITE}m" | |
local SEPARATOR_FORMAT_3="\e[${NONE};${FG_WHITE};${BG_DEFAULT}m" | |
local TRIANGLE=$'\uE0B0' | |
local SEPARATOR_1=$SEPARATOR_FORMAT_1$TRIANGLE | |
local SEPARATOR_2=$SEPARATOR_FORMAT_2$TRIANGLE | |
local SEPARATOR_3=$SEPARATOR_FORMAT_3$TRIANGLE | |
PROMPT_USER=$"$TEXT_FORMAT_1 \u " | |
PROMPT_PWD=$"$TEXT_FORMAT_2 \w " | |
# Escape the $(), to let bash evaluate the function every time | |
PROMPT_EXTRA=$"$TEXT_FORMAT_3 \$(__toolbox_maybe_ps1)\$(__jhbuild_maybe_ps1)\$(__git_maybe_ps1)" | |
PROMPT_FORMAT=$"$NO_FORMAT" | |
PS1="${PROMPT_USER}${SEPARATOR_1}${PROMPT_PWD}${SEPARATOR_2}${PROMPT_EXTRA}${SEPARATOR_3}${PROMPT_FORMAT}\n" | |
} | |
# Old PS1 | |
#PS1='\e[32m\u\e[39m@\e[32m\h\e[39m:\e[4;33m$(__jhbuild_maybe_ps1)\e[0;31m\w \e[1;34m$(__git_maybe_ps1 "(%s)")\e[0;39m\$\e[0m\n' | |
#PS1='\e[32m\u\e[39m@\e[32m\h\e[39m:\e[31m\w \e[39m\$\e[0m\n' | |
generate_prompt | |
unset generate_prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment