* variable containing the current command
@ 1999-05-26 20:23 benjamin
1999-05-26 21:40 ` Sweth Chandramouli
0 siblings, 1 reply; 6+ messages in thread
From: benjamin @ 1999-05-26 20:23 UTC (permalink / raw)
To: zsh-users
Is there a zsh environment variable that contains the current command
so that it can be referenced in preexec() or precmd() (or ideally both)?
e.g.
precmd() { echo "Just did:$CURRENT_CMD" }
preexec() { echo "Ready to do:$CURRENT_CMD" }
localhost[1]% ls
Ready to do:ls
foo bar snafu tarfu
Just did:ls
localhost[2]%
Ben
--
Benjamin Korvemaker
benjamin@cs.ualberta.ca
I have yet to meet a C compiler that is more friendly
and easier to use than eating soup with a knife.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: variable containing the current command
1999-05-26 20:23 variable containing the current command benjamin
@ 1999-05-26 21:40 ` Sweth Chandramouli
1999-05-26 22:17 ` Bart Schaefer
0 siblings, 1 reply; 6+ messages in thread
From: Sweth Chandramouli @ 1999-05-26 21:40 UTC (permalink / raw)
To: zsh-users
On Wed, May 26, 1999 at 02:23:10PM -0600, benjamin@cs.ualberta.ca wrote:
> Is there a zsh environment variable that contains the current command
> so that it can be referenced in preexec() or precmd() (or ideally both)?
>
> e.g.
>
> precmd() { echo "Just did:$CURRENT_CMD" }
> preexec() { echo "Ready to do:$CURRENT_CMD" }
>
> localhost[1]% ls
> Ready to do:ls
> foo bar snafu tarfu
> Just did:ls
> localhost[2]%
$_ is almost what you are looking for; it is supposed to be set for
any command to the full name of that command. if you use it as you use
CURRENT_CMD above, however, you get something like this:
(astaroth/1)~: precmd() { echo "Just did:$_" }
Just did:precmd
(astaroth/2)~: preexec() { echo "Ready to do:$_" }
Just did:preexec
(astaroth/3)~: ls
Ready to do:preexec
appconfig Mail News public_html working
bin mail news src www
docs misc nohup.out tmp
Just did:ls
(astaroth/4)~:
i could never figure out why it acts that way, though, so i've
never really used it.
-- sweth.
--
Sweth Chandramouli
IS Coordinator, The George Washington University
<sweth@gwu.edu> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F)
<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: variable containing the current command
1999-05-26 21:40 ` Sweth Chandramouli
@ 1999-05-26 22:17 ` Bart Schaefer
1999-05-26 22:50 ` Michael Barnes
1999-05-28 23:13 ` benjamin
0 siblings, 2 replies; 6+ messages in thread
From: Bart Schaefer @ 1999-05-26 22:17 UTC (permalink / raw)
To: zsh-users
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: variable containing the current command
1999-05-26 22:17 ` Bart Schaefer
@ 1999-05-26 22:50 ` Michael Barnes
1999-05-31 5:46 ` Bart Schaefer
1999-05-28 23:13 ` benjamin
1 sibling, 1 reply; 6+ messages in thread
From: Michael Barnes @ 1999-05-26 22:50 UTC (permalink / raw)
To: zsh-users
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: variable containing the current command
1999-05-26 22:50 ` Michael Barnes
@ 1999-05-31 5:46 ` Bart Schaefer
0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 1999-05-31 5:46 UTC (permalink / raw)
To: Michael Barnes, zsh-users
On May 26, 6:50pm, Michael Barnes wrote:
} Subject: Re: variable containing the current command
}
} 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.
I'm not sure why you say $1 does not get set properly. $1 gets set to
the entire command line, which is exactly how it's documented:
`preexec'
Executed just after a command has been read and is about to be
executed. If the history mechanism is active, the string to be
executed is passed as an argument. ^^^^!!!!!!^^^^^^
^^^^^^^^^^^^^^^^^^^^^^!!^^^^^^^^^
Is that in fact what you see, or is there a bug that I can't reproduce?
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: variable containing the current command
1999-05-26 22:17 ` Bart Schaefer
1999-05-26 22:50 ` Michael Barnes
@ 1999-05-28 23:13 ` benjamin
1 sibling, 0 replies; 6+ messages in thread
From: benjamin @ 1999-05-28 23:13 UTC (permalink / raw)
To: zsh-users
Thanks. That's EXACTLY what I was looking for. Reading the man page
carefully reveals that I am too stupid to live. :)
Ben
Bart Schaefer said:
> 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.
>
--
Benjamin Korvemaker
benjamin@cs.ualberta.ca
The programmer's national anthem is 'AAAAAAAARRRRGHHHHH!!'.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1999-05-31 5:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-26 20:23 variable containing the current command benjamin
1999-05-26 21:40 ` Sweth Chandramouli
1999-05-26 22:17 ` Bart Schaefer
1999-05-26 22:50 ` Michael Barnes
1999-05-31 5:46 ` Bart Schaefer
1999-05-28 23:13 ` benjamin
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).