* have zsh invoke a command/script but not exit
@ 2005-05-30 15:51 Tim K. (Gmane)
2005-05-30 18:06 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Tim K. (Gmane) @ 2005-05-30 15:51 UTC (permalink / raw)
To: zsh-users
Hello,
Is it possible to start zsh and invoke some other command/script but
upon command completion to return to interactive mode rather than exit
from zsh? Something like this:
zsh -i -c ls
so that after the ls command is finished I'm left in an interactive shell.
The only way I can think off is to put some hack in my .zshrc where if
some env variable is set it will run that command at the end of my
.zshrc file, e.g.
RUN_CMD='ls *.txt' zsh -i
and .zshrc would check for $RUN_CMD and run it at the end.
But even this way I'm struggling with arguments passed to my command,
how would I run RUN_CMD from .zshrc? Would this be the way to do it:
eval "$RUN_CMD"
Is there a better way to do it?
Thanks for your help.
--
Tim
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: have zsh invoke a command/script but not exit
2005-05-30 15:51 have zsh invoke a command/script but not exit Tim K. (Gmane)
@ 2005-05-30 18:06 ` Bart Schaefer
2005-05-31 14:28 ` Tim K. (Gmane)
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2005-05-30 18:06 UTC (permalink / raw)
To: zsh-users
On May 30, 8:51am, Tim K. (Gmane) wrote:
}
} Is it possible to start zsh and invoke some other command/script but
} upon command completion to return to interactive mode rather than exit
} from zsh?
After the startup files are finished, zsh reads commands from exactly
one of four places: The argument of the -c option, the current terminal,
the standard input, or a script file.
A script file is assumed if zsh has arguments but no options specifying
one of the other sources. The documentation implies that -s forces zsh
to read from stdin, but in fact the -s option only determines whether
any further arguments are taken as the name of a script file; when both
-i and -s appear, -i takes precedence to force input from the terminal.
The -c option overrides both -i and -s, except that the .zshrc file is
read when both -i and -c appear.
The prompt is printed only in interactive mode, and you can't change the
value of that option after startup, so it's impossible to be prompted
after a command has been read from anywhere other than the terminal
(unless you run your own input loop e.g. using "vared").
} The only way I can think off is to put some hack in my .zshrc where if
} some env variable is set it will run that command at the end of my
} .zshrc file
How about using $@ instead of an environment variable?
if [[ $1 == eval ]]
then
"$@"
set --
fi
Then you run this as
zsh -is eval 'ls *.txt'
You could even skip the requirement that "eval" be the first word:
if (( $# ))
then
eval "$@"
set --
fi
However, using "eval" as a keyword there means that you can still use
zsh -is with other argument strings without treating them as commands.
I like this because it lends itself to becoming an alias.
alias zshi='zsh -is eval '
(The trailing space is for completion purposes.)
Hmm. Depending on how you expect to use that, you might want to change
the .zshrc part to:
if [[ $1 == eval ]]
then
"${(q)@}"
set --
fi
You can see the difference if you run:
zshi echo foo \; echo bar
zshi 'echo foo ; echo bar'
Try each of those both with the (q) and without, and pick the way that
makes the most sense to you.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: have zsh invoke a command/script but not exit
2005-05-30 18:06 ` Bart Schaefer
@ 2005-05-31 14:28 ` Tim K. (Gmane)
0 siblings, 0 replies; 3+ messages in thread
From: Tim K. (Gmane) @ 2005-05-31 14:28 UTC (permalink / raw)
To: zsh-users
Thanks for your reply. I have to go learn about the advanced (at least
to me) things you suggested below.
Tim
Bart Schaefer wrote:
>On May 30, 8:51am, Tim K. (Gmane) wrote:
>}
>} Is it possible to start zsh and invoke some other command/script but
>} upon command completion to return to interactive mode rather than exit
>} from zsh?
>
>After the startup files are finished, zsh reads commands from exactly
>one of four places: The argument of the -c option, the current terminal,
>the standard input, or a script file.
>
>A script file is assumed if zsh has arguments but no options specifying
>one of the other sources. The documentation implies that -s forces zsh
>to read from stdin, but in fact the -s option only determines whether
>any further arguments are taken as the name of a script file; when both
>-i and -s appear, -i takes precedence to force input from the terminal.
>The -c option overrides both -i and -s, except that the .zshrc file is
>read when both -i and -c appear.
>
>The prompt is printed only in interactive mode, and you can't change the
>value of that option after startup, so it's impossible to be prompted
>after a command has been read from anywhere other than the terminal
>(unless you run your own input loop e.g. using "vared").
>
>} The only way I can think off is to put some hack in my .zshrc where if
>} some env variable is set it will run that command at the end of my
>} .zshrc file
>
>How about using $@ instead of an environment variable?
>
> if [[ $1 == eval ]]
> then
> "$@"
> set --
> fi
>
>Then you run this as
>
> zsh -is eval 'ls *.txt'
>
>You could even skip the requirement that "eval" be the first word:
>
> if (( $# ))
> then
> eval "$@"
> set --
> fi
>
>However, using "eval" as a keyword there means that you can still use
>zsh -is with other argument strings without treating them as commands.
>
>I like this because it lends itself to becoming an alias.
>
> alias zshi='zsh -is eval '
>
>(The trailing space is for completion purposes.)
>
>Hmm. Depending on how you expect to use that, you might want to change
>the .zshrc part to:
>
> if [[ $1 == eval ]]
> then
> "${(q)@}"
> set --
> fi
>
>You can see the difference if you run:
>
> zshi echo foo \; echo bar
> zshi 'echo foo ; echo bar'
>
>Try each of those both with the (q) and without, and pick the way that
>makes the most sense to you.
>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-05-31 14:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-30 15:51 have zsh invoke a command/script but not exit Tim K. (Gmane)
2005-05-30 18:06 ` Bart Schaefer
2005-05-31 14:28 ` Tim K. (Gmane)
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).