add bash completion example #2339

Merged
merged 7 commits into from Aug 29, 2012

Conversation

Projects
None yet
4 participants

load with: . ipython-completion.bash

still work in progress
it doesn't get all flags options yet, most importantly --profile and the available profiles are missing but it might already be useful to some.

@juliantaylor juliantaylor add bash completion example
load with: . ipython-completion.bash
30a49ca

This pull request fails (merged 30a49ca into f4616c9).

Owner

Carreau commented Aug 26, 2012

That's cool, I tried some time ago but my knowledge in bash scripting is close to 0.
So i'll just trust you on this one.

Is it possible to make it work when using python ipython.py ... ?

not directly, you have to make an alias (alias somename=...) and change the last argument complete to the alias

Owner

minrk commented Aug 27, 2012

after playing with it, it seems to do quite nicely. Well done! Anything more you want to do on this, or should we go ahead and merge it?

An option that might be quicker and actually more complete could be to base the completions on the output of --help-all, and cache that output for a given subcommand.

merging can be postponed, I also posted it for some feedback

using help-all would would be more complete but it is also slower on startup, on the other hand its not so bad with caching.
I might change it to use that, assuming the format is stable.

of the help-all output, can everything but Unicode> and Integer be skipped?
Or is it possible to enter a Bool or Dict from the terminal?

Owner

Carreau commented Aug 27, 2012

Yes you can enter bool from terminal.
you can do

ipython --IPCompleter.greedy=True
Owner

minrk commented Aug 27, 2012

It is possible to enter bools, lists, dicts, etc. at the terminal (with varying degrees of shenanigans):

ipython --TerminalIPythonApp.quick=True \
        --ScriptMagics.script_magics='["bash", "ruby"]' \
        --ScriptMagics.script_paths='{"bash": "/usr/local/bin/bash", "ruby": "/usr/bin/ruby"}'

This pull request passes (merged e0bc767 into f4616c9).

This pull request passes (merged 8a59f55 into f4616c9).

This pull request passes (merged d109c45 into f4616c9).

its now using help all and completes bundled and user profiles
maybe the caching could be made a bit more fine grained, but I'm not sure if its worth it

Owner

Carreau commented Aug 29, 2012

could it append = to argument that expect value ?
like

ipython qtconsole --IPCompleter.gr<tab>
ipython qtconsole --IPCompleter.greedy=[cursor]

instead of

ipython qtconsole --IPCompleter.greedy[space][cursor]

?

Owner

Carreau commented Aug 29, 2012

I came up with not removing = sign and appending space to line not ending with =

opts=$(ipython ${url} --help-all | grep -E "^-{1,2}[^-]" | sed -e "s/<.*//" |  sed -e "s/\([^=]\)$/\1 /")

and complete -o nospace but it seem to trim the space on its own...

you have to change the IFS to avoid it splitting on space:

local IFS=$'\t\n'
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )

but why do some command line options not work without the equal sign in the firstplace?
other similar looking ones like --log-level work without

Owner

Carreau commented Aug 29, 2012

IIUC ,that is because the unreconised flags of the command line argument are assumed to be config option for configurable class. Then those argument are parsed by the KVLoader that also read the config file which plain python, and need an =

This allows to do things like

$ ipython --Unexisting.config='myoption' --Class.traitsatribut=6

(which will work)

And options that support not having = or don't take arguments are just added for convenience.

added support for the equal signs and improved compatibility with older bash

Owner

Carreau commented Aug 29, 2012

That's a great addition !
Merging !
( waiting for the same for other shell :-) )

@Carreau Carreau added a commit that referenced this pull request Aug 29, 2012

@Carreau Carreau Merge pull request #2339 from juliantaylor/bash-completion
add bash completion example
8756d12

@Carreau Carreau merged commit 8756d12 into ipython:master Aug 29, 2012

@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014

@Carreau Carreau Merge pull request #2339 from juliantaylor/bash-completion
add bash completion example
f25c21c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment