From b156901695c8f1b54a70ab0fe3a5b2b3bce2eaf5 Mon Sep 17 00:00:00 2001 From: "Andrew R. M." Date: Sun, 12 May 2024 22:58:50 -0400 Subject: [PATCH] Added conditional coloring of bash prompt dependent on direnv status --- bash/.bashrc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bash/.bashrc b/bash/.bashrc index 7497f46..17f9e4f 100644 --- a/bash/.bashrc +++ b/bash/.bashrc @@ -12,9 +12,21 @@ no_color="\001$(tput sgr0)\002" export PS1="${green}\$${no_color} " +export DIRENV_PS1="${red}\$${no_color} " if [ "${HOSTNAME}" != "crypt" ] && [ "${HOSTNAME}" != "tomb" ] || [ "${SSH_TTY}" != "" ]; then PS1="${PS1}${blue}${HOSTNAME} ${PS1}" + DIRENV_PS1="${PS1}${blue}${HOSTNAME} ${PS1}" fi +export ORIG_PS1=${PS1} + +update_prompt() { + if direnv status | grep -iq 'RC allowed true'; then + PS1=${DIRENV_PS1} + else + PS1=${ORIG_PS1} + fi +} +PROMPT_COMMAND="update_prompt; $PROMPT_COMMAND" # Continuation Prompt: "> " in cyan export PS2="${cyan}>${no_color} "