* problem with function in prompt
@ 2011-03-24 20:23 Stephen Prater
2011-03-24 22:09 ` René 'Necoro' Neumann
0 siblings, 1 reply; 2+ messages in thread
From: Stephen Prater @ 2011-03-24 20:23 UTC (permalink / raw)
To: zsh-users
I have the following function in a sourced file..
function free_mem() {
FM=$(ruby -e '
x = `vm_stat`.each_line.to_a[0..4].join.scan(/([0-9]*?)
\./).flatten.map { |i| (i.to_i * 4096) / 1000000 };
y = `sysctl hw.memsize`.split(/:\s/).last.to_i / 1000000;
puts "%F{82}#{x[0]}%f/%F{yellow}#{x[2]}%f/%F{69}#{y}%f";')
echo $FM
}
and then in my prompt i have this:
$(free_mem)
The problem is that it never re-executes the function in the prompt ----
setopt prompt_subst
PROMPT_INFO="$(draw f21 ul hbar) $(host_name)- %L
$(draw f21 ll hbar) $(dir_name) $(free_mem)"
DEF_PROMPT="${(e)${PROMPT_INFO}} %F{cyan} [ %f"
INS_MODE_PROMPT="${(e)${PROMPT_INFO}} %F{red} [ %f"
The value that appears in the prompt is always the same as the one
when the shell was initially executed.
I tried placing it in a variable within precmd and then using that
variable in the prompt like this:
precmd() {
FREE_MEM=$(free_mem)
}
PROMPT="$FREE_MEM"
but that didn't work either
If I call free_mem directly from the prompt (or echo FREE_MEM) it
outputs the correct string... so what am I missing?
stephen
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: problem with function in prompt
2011-03-24 20:23 problem with function in prompt Stephen Prater
@ 2011-03-24 22:09 ` René 'Necoro' Neumann
0 siblings, 0 replies; 2+ messages in thread
From: René 'Necoro' Neumann @ 2011-03-24 22:09 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 868 bytes --]
Am 24.03.2011 21:23, schrieb Stephen Prater:
>
> The problem is that it never re-executes the function in the prompt ----
>
> setopt prompt_subst
>
> PROMPT_INFO="$(draw f21 ul hbar) $(host_name)- %L
> $(draw f21 ll hbar) $(dir_name) $(free_mem)"
> DEF_PROMPT="${(e)${PROMPT_INFO}} %F{cyan} [ %f"
> INS_MODE_PROMPT="${(e)${PROMPT_INFO}} %F{red} [ %f"
>
>
> The value that appears in the prompt is always the same as the one when
> the shell was initially executed.
You should use FOO='$bla' instead of FOO="$bla" -- with the latter, $bla
is evaluated while assigning -- with the first one, $bla is evaluated
while evaluating $FOO.
This means, with your current way, the variables and functions are all
computed while setting the prompt variable -- and then there is nothing
left to evaluate while printing the prompt :)
HTH,
- René
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-03-24 22:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-24 20:23 problem with function in prompt Stephen Prater
2011-03-24 22:09 ` René 'Necoro' Neumann
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).