I'm having the hardest time trying to get dynamically evaluated command output in my PS1
prompt with zsh on Ubuntu 17.10. Here are a few attempts I've made (I begin in directory /abc
, and the prompt is in bold):
$ export PS1="$(pwd) > " /abc > cd /def /abc > pwd /def /abc > export PS1="\$(pwd) > " $(pwd) > export PS1='$(pwd) > ' $(pwd) > export PS1='\$(pwd) > ' \$(pwd) > [ragequit]
The first result is the closest, but it looks like the pwd
command is being evaluated only once when I define the PS1
variable. Clearly there's something that I don't understand. What can I do to get $(<cmd>)
reevaluated every time the command prompt is displayed?
precmd
function and settingpsvar
tends to be easier for doing complicated things than usingprompt_subst
. And for simple things there's prompt expansion, e.g.%~
for the current directory.precmd
. That's howvcs_info
bundled with zsh does it.vcs_info
. (I don't either.) I'm saying that if you do something similar, you'll have an easier time usingprecmd
and keepingPS1
itself very simple.