Currently, my bash prompt prints a new line after the output of the previous command via a '\n' in my PS1 value. Here is a look at my ~/.bash_profile that gets loaded when I enter the shell:
function nonzero_return() {
local RETVAL=$?
[[ $RETVAL -ne 0 ]] && echo "❌($RETVAL)" || echo "✅"
}
PS1='\[\e]0;Git Bash: $MSYSTEM\007\]\n\[\e[31m\]`nonzero_return`\[\e[32m\] \u@\h \[\e[35m\]\w\[\e[36m\]`__git_ps1`\e[0m\n$'
and my prompt looks like this:
✅ User@PC ~/Git
$
✅ User@PC ~/Git
$
However, when I activate a Python Virtual Environment my prompt will look like this:
(venv)
✅ User@PC ~/Git
$
(venv)
✅ User@PC ~/Git
$
I would like to maybe create a function that checks the PS1 value to see if a Virtual Environment is active (maybe by evaluating PS1 to see if it starts with a '(' ) and, if it does, add a '\n' to the beggining of PS1 so that the prompt would then look like this:
(venv)
✅ User@PC ~/Git
$
(venv)
✅ User@PC ~/Git
$
I know I could probably add to the Python activate script but I'd like the shell to do it interactively for me.