Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from stackoverflow.com Jun 2 '11 at 19:06

This question came from our site for professional and enthusiast programmers.

up vote 14 down vote accepted

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

share|improve this answer
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. – Dennis Williamson Jun 4 '11 at 11:28
This requires that setopt PROMPT_SUBST has occurred earlier in the file. Otherwise, it will just echo the prompt out literally. – Nick Meharry Mar 28 '12 at 23:10

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).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.