[IPython-user] ipython -p sh questions
Ville M. Vainio
vivainio@gmail....
Sun Mar 9 08:49:42 CDT 2008
On Tue, Mar 4, 2008 at 7:28 PM, Ville M. Vainio <vivainio@gmail.com> wrote:
> > > What does !$ do? If there in no equivalent yes, we can do it ;-)
>
> > !$ designates the last argument of the preceding command. (!!:n
> > designates the n-th argument of the preceding command). I thought about
> > adding it to my config files but I'm always loathe to hack things in
> > when someone might've already done it better. :-)
>
> Ah, such a thing does not exist but it could be useful. Hell, we could
> add it to jobctrl as well. $! does not sit well in IPython due to Itpl
> interpolation (even if it could be done with prefilters), but $LA
> could be handy for this purpose. I.e. in jobctrl shell hook we could
> set global variable LA in user_ns to have the last arg, and $LA will
> naturally work.
This has now been added to the sh profile (in bzr). That is, you can
use $LA in system and magic commands (and LA() in normal python code):
[C:opt/Console2]|2> hello world
------------------------------------------------------------
File "<ipython console>", line 1
hello world
^
SyntaxError: invalid syntax
[C:opt/Console2]|3> echo $LA
world
[C:opt/Console2]|4> LA()
<4> 'world'
The implementation is simple:
http://bazaar.launchpad.net/~ipython/ipython/stable-dev/revision/38
It is a bit of a 'hack', but it's a nondisruptive one; if you assign
to the LA variable, $LA will stop working but that's "safer" than
disallowing the users the use of variable named 'LA'...
--
Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'
More information about the IPython-user
mailing list