[IPython-user] Using ipython as a bash replacement

Fernando Perez fperez at colorado.edu
Sat Apr 10 16:02:02 CDT 2004


> The alias command is awesome, but I think a small detail of its behaviour
> should be tweaked to make it more shell-friendly -- the tab-completion.
> 
> Currently, it's setup to first search python variables, then if there are
> no matches it searches for matching filenames. Doing it in that order is
> inconvenient because you're going to be running the alias on a file most
> of the time.

This is a nice idea, and a perfectly reasonable request.  Unfortunately, a 
fairly tricky one to implement.  The reason is that the completer code only 
knows about the _word_ it is currently completing, not about the whole line.

In order to do context-sensitive completions, I'd need to know the whole line, 
so I could decide whether it's an alias, another magic, or regular python 
code.  For this reason, I don't see a way of having a changing completion 
policy.  It would be possible to flip the order ([filnames, python] vs 
[python, filenames]), but this would be a _global_ change.  Obviously I can't 
do that for ipython's default behavior, but it's certainly a reasonable option 
which could be introduced for a more 'python-bash' hybrid as has been the 
subject of recent discussion.

If anyone knows how to implement, in the context of GNU readline, 
context-sensitive completions, I'm all ears.

> (BTW: Is there a way to use python symbols on an alias' commandline,
> where it expands them to strings first, so you could do something like:
> ls someobject.get_dir()?)

Not really, and I don't see the name handling issues to be easy either.  This 
begins to show you one of the very tricky issues at play in mixing python with 
filesystem access: that of variable name expansion.  The shells and Perl 
bypass this issue via their $name convention.  While for programming, I FAR 
prefer python's absence of $ to evaluate variables, in the context of 
filesystem access this makes some things difficult.

For example, in a shell you can do this:

[~/tmp]> set ls='echo hello'
[~/tmp]> ls
IPython-0.5.0.tar.gz  pyamazonpres.tgz
[~/tmp]> $ls
hello

The shell has two separate namespaces, and 'ls' can be interpreted in two 
different ways depending on the presence of a '$' indicator.  In python, how 
exactly can we do this?

This leads me to think that for _any_ shell-like implementation based on 
(i)python, which intends to interact seamlessly with the underlying 
filesystem, some kind of explicit name disambiguation will be necessary.

I'll try to write up more about this topic in a separate message, collecting 
the recent ideas which have popped up on this list.

> Anyhow, this behaviour would be better if it was reversed for aliases
> (serach filenames first, then symbols).
> 
> Heh, sorry, this is kinda a long message for such a simple issue.
> 
> iPython is one of my favorite tools, by the way. I was thinking of
> writing a little Win32-native wrapper for it so that you can run it in a
> Window with all the proper colours and getline support.  I haven't
> found a good solution yet (I still use it through SSH). Do you know if
> anyone else has thought of working on something like this?

I think that using Gary Bishop's tools (google uncpythontools) all of this 
works fairly well, in a regular Windows command window (not using Cygwin).

Cheers,

f




More information about the IPython-user mailing list