From 79a87884db3c72b13fa695c9a8b898df86e28b15 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Sun, 3 Dec 2023 00:18:23 +0100 Subject: [PATCH] Moved my Python prompt to https://git.afpy.org/mdk/python-prompt. --- .bashrc | 51 +++------------------------------------------------ 1 file changed, 3 insertions(+), 48 deletions(-) diff --git a/.bashrc b/.bashrc index df7489c..4a6823c 100644 --- a/.bashrc +++ b/.bashrc @@ -66,7 +66,7 @@ alias rekey='ssh-add -e /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so >/dev/null 2> export PYTHONDEVMODE=y -for extra in /etc/bash_completion ~/.bash_aliases ~/.my_bashrc ~/.git-prompt.sh ~/clones/mdk/compile-python/compile-python.sh +for extra in /etc/bash_completion ~/.bash_aliases ~/.my_bashrc ~/.git-prompt.sh ~/clones/mdk/compile-python/compile-python.sh ~/clones/mdk/python-prompt/python-prompt.sh do if [ -f "$extra" ] then @@ -74,50 +74,6 @@ do fi done -trim() { - local var="$*" - # remove leading whitespace characters - var="${var#"${var%%[![:space:]]*}"}" - # remove trailing whitespace characters - var="${var%"${var##*[![:space:]]}"}" - printf '%s' "$var" -} - -shortest() -{ - # Returns the shortest of two strings - if [[ ${#1} -lt ${#2} ]] - then - printf "%s" "$1" - else - printf "%s" "$2" - fi - -} - -python_ps1() -{ - local relative venvpath pyversion _ - - venvpath="$(which python 2>/dev/null)" - venvpath="${venvpath%/bin/python}" - - if [[ -z "$venvpath" ]] || [[ "$venvpath" == "/usr" ]]; then - return - fi - - relative="$(realpath --relative-to="$(pwd)" -s "$venvpath")" - venvpath="$(shortest "$venvpath" "$relative")" - - if [[ "$venvpath" == ".venv" ]]; then - venvpath="" # No need to tell me my venv is in .venv, I can guess it. - fi - - read -r _ pyversion <<<"$(python --version)" - - printf "$1" "$(trim "$venvpath $pyversion")" -} - if [[ "$TERM" != 'dumb' ]] then _TITLE="\[\e]0;\H \W\a\]" @@ -138,9 +94,8 @@ PY_BLUE_FG='\e[38;2;53;112;160m' PY_BLUE_BG='\e[48;2;53;112;160m' PY_YELLOW_FG='\e[38;2;255;222;87m' PY_YELLOW_BG='\e[48;2;255;222;87m' -# 🬫🬛 -# 🭮🭬 -PY_PS1='$(python_ps1 "${PY_BLUE_FG}🭮${PY_BLUE_BG}${PY_YELLOW_FG}  %s \e[0m${PY_BLUE_FG}🭬\e[0m")' + +PY_PS1='$(python_prompt "${PY_BLUE_FG}🭮${PY_BLUE_BG}${PY_YELLOW_FG}  %s \e[0m${PY_BLUE_FG}🭬\e[0m")' GIT_PS1='$(__git_ps1 "${GIT_RED_FG}🭮${GIT_RED_BG}\e[97m  %s \e[0m${GIT_RED_FG}🭬\e[0m")' PS1="${_TITLE}${_PREV_FAIL}${USERNAME_COLOR}\u\e[0m@${HOSTNAME_COLOR}\H\e[0m:\e[32m\w\e[0m${PY_PS1}${GIT_PS1}\n\$ "