This might be a bit fringe, but I recently moved to zsh and am having a problem customizing my shell prompt.
Part of my .zshrc looks like this:
# keeping this simple right now by just printing the date, but imagine this function would look for something specific when moving to a new directory each time
function parse_special {
print $(date)
}
autoload -U colors && colors
PS1="%{$fg[green]%}%n@%m %{$fg[blue]%}%c %{$fg[yellow]%}%{$(parse_special)%} %{$reset_color%}%# "
When I launch terminal, everything looks good; my prompt is what I expect:
me@someHost ~ Wed Aug 8 22:56:22 PDT 2012 %
But when I cd to another directory, it appears my parse_special function is not called again to recompute my custom prompt (notice the date is not changing):
me@someHost ~ Wed Aug 8 22:56:22 PDT 2012 % cd .ssh
me@someHost .ssh Wed Aug 8 22:56:22 PDT 2012 % cd ../workspace
me@someHost workspace Wed Aug 8 22:56:22 PDT 2012 %
Is there any way I can tell zsh to recompute the prompt each time it is about to show it?
thanks a lot for any suggestions.
reply to cjhveal
It seems like PS1 does not like to get set by single quoted values. I tried the following:
local tp1="%{$fg[green]%}%n@%m%{$reset_color%}"
PS1="${tp1}"
print "PS1 set by tp1: ${PS1}"
local tp2='%{$fg[green]%}%n@%m%{$reset_color%}'
PS1="${tp2}"
print "PS1 set by tp2: ${PS1}"
And got this output
#inner stuff was green
PS1 set by tp1: %{%}%n@%m%{%}
#everything was uncolored
PS1 set by tp2: %{$fg[green]%}%n@%m%{$reset_color%}
I should also add, based on cjhveal's suggestion, here is what I literally tried. Again, the single quotes seem to be messing things up
function parse_special {
print $(date)
}
autoload -U colors && colors
local prompt_user='%{$fg[green]%}%n@%m%{$reset_color%}'
local prompt_root='%{$fg[red]%}%n@%m%{$reset_color%}'
local prompt_dir='%{$fg[blue]%}%c%{$reset_color%}'
local prompt_special='%{$fg[yellow]%}%{$(parse_special)%}%{$reset_color%}'
PS1="${prompt_user} ${prompt_dir}${prompt_special}%# "