I would like to update the bash prompt inside a script. Essentially, I have to use a VPN to remotely work on another computer and would like it to get reflected by the bash prompt. Unfortunately whatever I change in PS1 is not update in the bash-shell.
A part of my script that changes PS1 is the following:
# ...
__RESULT=${__RESULT,,}
# CONDITION: set prompt
PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
case $__RESULT in
*enabled* | *enable* | *connected* | *connect*)
PS1='(gp on) \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
;;
esac
export PS1
However, it's not working. I found another question, which suggests setting PROMPT_COMMAND
. I have followed the suggestions but it is neither working. Also, I am afraid this variable might already be used by another application and I wouldn't really like to overwrite it. So the second version:
__RESULT=${__RESULT,,}
# CONDITION: set prompt
function gp_set_prompt {
PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
case $__RESULT in
*enabled* | *enable* | *connected* | *connect*)
PS1='(gp on) \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
;;
esac
export PS1
set_conda
}
export PROMPT_COMMAND=gp_set_prompt
At this point, I am not quite sure what else I can do. Any help? Thanks.
source
in the~/.bashrc
?PS1
) in a script that is executing in a separate child environment.~/.bashrc
. yourscript
orsource yourscript
? (see also the remark by Kusalananda)