zsh-users
 help / color / mirror / code / Atom feed
From: Stephen Prater <stephenp@agrussell.com>
To: zsh-users@zsh.org
Subject: problem with function in prompt
Date: Thu, 24 Mar 2011 15:23:48 -0500	[thread overview]
Message-ID: <F8A44F57-744F-41C4-B030-8170FCF1F03D@agrussell.com> (raw)

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


             reply	other threads:[~2011-03-24 20:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-24 20:23 Stephen Prater [this message]
2011-03-24 22:09 ` René 'Necoro' Neumann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F8A44F57-744F-41C4-B030-8170FCF1F03D@agrussell.com \
    --to=stephenp@agrussell.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).