zsh-users
 help / color / mirror / code / Atom feed
From: "Michael Barnes" <mibarnes@vt.edu>
To: zsh-users@sunsite.auc.dk
Subject: Re: variable containing the current command
Date: Wed, 26 May 1999 18:50:39 -0400	[thread overview]
Message-ID: <19990526185039.A10504@vt.edu> (raw)
In-Reply-To: <990526221741.ZM22768@candle.brasslantern.com>; from Bart Schaefer on Wed, May 26, 1999 at 10:17:41PM +0000

here is my preexec

~ which preexec
preexec () {
	word=$* 
	word=$word[(w)0] 
	case $word in
		cd*|ls*)  ;;
		*) print -Pn "\e]2;%n@%m $word \a" ;;
	esac
}

for some reason $1 does not get set properly under 3.0.5 extended so I
manually parse it out from $*, dunno about newer versions.

Mike

On Wed, May 26, 1999 at 10:17:41PM +0000, Bart Schaefer wrote:
> On May 26,  2:23pm, benjamin@cs.ualberta.ca wrote:
> > Subject: variable containing the current command
> > Is there a zsh environment variable that contains the current command
> > so that it can be referenced in preexec() or precmd() (or ideally both)?
> 
> In preexec, the positional parameter $1 holds the entire command line just
> as it was read from the terminal (after history expansion but before any
> other expansions/substitutions).
> 
> You could have preexec copy this to a global parameter where precmd can
> see it later.
> 
> On May 26,  5:40pm, Sweth Chandramouli wrote:
> > Subject: Re: variable containing the current command
> > 	$_ is almost what you are looking for; it is supposed to be set for
> > any command to the full name of that command.
> 
> That's not quite correct.  From the doc:
> 
> `_'
>      The last argument of the previous command.  Also, this parameter
>      is set in the environment of every command executed to the full
>      pathname of the command.
> 
> So it's only during the execution of a command that you can find the path
> of that command in $_.  Once you're back in the shell (as during precmd),
> you get the last word of the previous command line (not the first; try
> your "ls" example with some file name arguments to "ls").
> 
> As for this:
> 
> > (astaroth/3)~: ls
> > Ready to do:preexec
> 
> I suspect it has something to do with how or when preexec is executed.
> PWS could tell us more, but he's out for a few days.


  reply	other threads:[~1999-05-26 22:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-05-26 20:23 benjamin
1999-05-26 21:40 ` Sweth Chandramouli
1999-05-26 22:17   ` Bart Schaefer
1999-05-26 22:50     ` Michael Barnes [this message]
1999-05-31  5:46       ` Bart Schaefer
1999-05-28 23:13     ` benjamin

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=19990526185039.A10504@vt.edu \
    --to=mibarnes@vt.edu \
    --cc=zsh-users@sunsite.auc.dk \
    /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).