-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bash Programmable Completion for Spack #459
Conversation
Let me know what you think about this particular implementation. There is still a lot of testing to do, and I'm not familiar with all of the Spack subcommands, so you'll have to help me out. One thing I would like to be able to do would be something like: $ spack install hdf5 %[]
%gcc@4.4.7 %gcc@5.3.0 %intel@16.0.1 %nag@6.0 %pgi@15.10-0
$ spack install hdf5 %gcc[]
%gcc@4.4.7 %gcc@5.3.0
$ spack install hdf5 %gcc@5.3.0 +[]
+cxx +debug +fortran +mpi +shared +szip
+threadsafe +unsupported
$ spack install hdf5 %gcc@5.3.0 +szip # the full command My current implementation strips out the flags and uses the remaining words to call a function with the same name (for example, Another idea I had, which I'm starting to realize might be a better solution, would be to use a single colossal case statement. That way I could group together all of the commands that should complete to a package spec. Thoughts on this method over the current method? I don't use zsh, but if there is enough interest, I'm sure we can get this working for zsh too. |
printf ", '%s'" "${array[@]:1}" | ||
echo "]" | ||
done | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_vars
and pretty_print
are just testing functions. I will remove them once we decide on a final solution and they are no longer needed.
@adamjstewart: this is awesome! Thanks for doing it. My worries about the current implementation are:
(2) kind of points to the need for a more context-sensitive spack parser. I had thought about making Spack's parser a bit smarter about distinguishing negative variants ( Would it be better to auto-generate some or most the bash completion code? I think that would generally work better and would ensure that the completion stuff doesn't get out of sync with the rest of spack. |
@tgamblin: Those are valid concerns. When I was first writing this, I thought about modifying each subcommand to have an option to print all options, or to somehow import each subcommand package into a python one-liner and print out the arguments in subparser, but decided that it would be a lot of work for a first implementation. Yes, we are currently adding a lot of new options and commands, but as Spack matures, this should taper off. If you can think of an easier way to get Spack to provide suggestions, let me know. As for using the Spack spec parser to provide suggestions, that would be nice. But I'm not sure where to get started. Do you have any suggestions as to where I should take this next? |
@adamjstewart: have you seen argcomplete? I was eyeing it as a first-cut solution for this a while ago. I think it would allow you to generate most of the boilerplate stuff, and it also provides ways to have the python code suggest completions in certain contexts. I would be curious whether it could cover the cases you've covered so far, and we could then work together to see if it could suggest completions for the spec parser. It would also remove the burden of maintaining completion code :) Want to check it out? |
I'll check it out. |
From what I can tell, pretty much every file in #!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK
import argcomplete, argparse
parser = argparse.ArgumentParser()
...
argcomplete.autocomplete(parser)
args = parser.parse_args() This would make argcomplete a required dependency of Spack. Other than that hurdle, it seems like argcomplete would let us do exactly what we want. Thoughts? |
Assuming Do you need to add it to each command in |
Maybe? I'll have to try it out. |
…38.1 Add ecmwf-atlas versions 0.38.0, 0.38.1
Do you have trouble remembering the ordering for
spack config edit compilers
? Do you have to runspack list 'py-*'
before installing any Python package because you can't remember the spelling ofpy-mysqldb1
? Don't you wish you could just tab-to-complete everything? Allow me to introduce Bash Programmable Completion for Spack!To add tab completion, simply source setup-env.sh from a Bash shell. Here is an example session. In the following examples, let the cursor be denoted by brackets, i.e. [], and assume that the user presses TABTAB at the cursor position: