11

My RPROMPT is set to display svn info using vcs_info. It reads RPROMPT=${vcs_info_msg_0_}. vcs_info is called using precmd(). However, RPROMPT doesn't update when I change directories. It works only if I invoke the prompt again (either by source ~/.zshrc or prompt ) and doesn't change upon chdir, unless I invoke the prompt again. Is there any way to change this behaviour?

24

Try putting single quotes around the variable value at assignment to delay evaluation:

RPROMPT='${vcs_info_msg_0_}'
3
  • why does the check mark go away when it gets migrated?
    – user5383
    Jun 3 '11 at 2:04
  • @user5383: You should ask that on meta.unix.stackexchange.com or meta.stackoverflow.com. I don't know (or only vaguely know) the answer. Jun 4 '11 at 11:28
  • 4
    This requires that setopt PROMPT_SUBST has occurred earlier in the file. Otherwise, it will just echo the prompt out literally. Mar 28 '12 at 23:10
1

Using a single-quote to delay evaluation works for defining dynamic aliases as well. Here's an alias, t, used to attach a new shell to an existing ssh agent process, which was started with an alias called ssh-start that writes out shell code to a file in a homedir:

mymistress:~> which ssh-start
ssh-start: aliased to eval `ssh-agent | tee ~/.ssh/ssh-agent.out` ; ssh-add ~/.ssh/id_rsa
mymistress:~> grep "alias t" .zshrc    
alias t="eval `cat ~/.ssh/ssh-agent.out`"
mymistress:~> which t
t: aliased to eval SSH_AUTH_SOCK=/tmp/ssh-nZBZp29804/agent.29804; export SSH_AUTH_SOCK;\nSSH_AGENT_PID=29805; export SSH_AGENT_PID;\necho Agent pid 29805;`

That definition of t is bad because it causes new information from a fresh run of ssh-start to be ignored. Changing the alias definition of t to be singly quoted in my .zshrc gives much better behavior:

mymistress:~> grep "alias t" .zshrc
alias t='eval `cat ~/.ssh/ssh-agent.out`'
mymistress:~> source ~/.zshrc
mymistress:~> which t
t: aliased to eval `cat ~/.ssh/ssh-agent.out`

Note the expansion of the definition of t as provided by which t, showing the effects of double quotes (immediate in-place expansion of commands or environment variables) vs. single quotes (delayed evaluation of commands and variables).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy