Skip to content
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

Feature/zsh completion #2356

Closed
wants to merge 10 commits into from
Closed

Conversation

Falkor
Copy link

@Falkor Falkor commented Nov 17, 2016

I was tired during the SC'16 tutorial to type all spack commands manually. So I decided to make a zsh completion file. As this is something new to me, it took me more time than planned and there are many rooms for improvement (in particular to handle automagically the specs) but I hope it would still be useful for the community.

Sebastien Varrette added 10 commits November 16, 2016 22:25
- cover main commands
- detailed option for 'activate' to 'compiler'

Signed-off-by: Sebastien Varrette <Sebastien.Varrette@uni.lu>
Signed-off-by: Sebastien Varrette <Sebastien.Varrette@uni.lu>
Signed-off-by: Sebastien Varrette <Sebastien.Varrette@uni.lu>
Signed-off-by: Sebastien Varrette <Sebastien.Varrette@uni.lu>
Signed-off-by: Sebastien Varrette <Sebastien.Varrette@uni.lu>
Signed-off-by: Sebastien Varrette <Sebastien.Varrette@uni.lu>
Signed-off-by: Sebastien Varrette <Sebastien.Varrette@uni.lu>
Signed-off-by: Sebastien Varrette <Sebastien.Varrette@uni.lu>
Signed-off-by: Sebastien Varrette <Sebastien.Varrette@uni.lu>
Signed-off-by: Sebastien Varrette <Sebastien.Varrette@uni.lu>
@adamjstewart
Copy link
Member

Hi @Falkor, this looks very useful! I actually created a bash completion file back in the day (see #459), but it wasn't accepted into Spack for various reasons. The main reason being that Spack is still under active development, and every time a new command is added or option flags are changed or renamed, it would need to be updated. Of course, I still use it every day and it works great for me. @tgamblin and I discussed this, and we think the best option moving forward would be to use argcomplete, a Python module that works together with argparse to determine what possible completions to use. This would have the benefit of working in all shells, and would allow complex spec analysis when doing a completion. See #459 for further discussion.

@Falkor
Copy link
Author

Falkor commented Nov 17, 2016

OK, but unless I'm wrong, argcomplete, genzshcomp (I used to generate this completion file) and just like equivalent gems in the ruby world (I'm more familiar with) such as thor-zsh_completion does not render a full bullet-proof scheme after executions -- you always had to manually reparse the generated output as it is hard for it to catch subtilities on the commands generation.... Your back to a manual parse/update
Anyway, as I said, I just found it useful for the community, if you or Todd found it useless until the CLI layout is fixed, just drop it ;) But as far as I can tell you as a new user, even an imperfect bash/zsh completion is better than nothing, especially if the CLI is so vast and diverse as for spack.

@davydden davydden mentioned this pull request Feb 2, 2017
@tgamblin
Copy link
Member

tgamblin commented Feb 3, 2017

Hi @Falkor: Sorry for the long delay on responding to this! I think this could be very useful; thanks for submitting it!

Is this ready to merge as-is or do you want to update things per @adamjstewart's #3026?

@tgamblin
Copy link
Member

tgamblin commented Feb 3, 2017

Sourcing this should probably be added somewhere in share/spack/setup-env.sh.

@adamjstewart
Copy link
Member

And it should probably be in the same directory. At least that's where I put mine.

@Falkor
Copy link
Author

Falkor commented Feb 4, 2017

I guess it can be merged as is. Compared to #3026, it add support for most --* options so it should be still useful.
As for usage instruction, it does not need to be sourced, if I'm not wrong it is better to complete the fpath variable of zsh with the directory holding _spack, as follows:

fpath=(path/to/spack/contrib/completion $fpath) # OR fpath=(path/to/spack/share/spack/zsh $fpath)

Thus I would suggest to complete setup-env.sh with something like:

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# [...]
if [[ -n ${ZSH_VERSION-}  ]]; then
    fpath=("${SCRIPTDIR}" $fpath)
    spack_zsh_completion_reload() {
       unfunction _spack && autoload -U _spack
    }
fi

@tgamblin
Copy link
Member

tgamblin commented Feb 6, 2017

@adamjstewart @trws @Falkor: Ok, #3026 is merged. Do any of you have time to tweak this PR so that it implements @Falkor's suggestion? I think the conditional he suggests for setup-env.sh is the right one.

@tgamblin
Copy link
Member

tgamblin commented Feb 6, 2017

And thanks again to @Falkor for submitting this!

@adamjstewart
Copy link
Member

I would try to tweak this, but I don't really know zsh at all. A few commands probably need to be updated though.

Copy link
Member

@alalazo alalazo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is now more than 2 years old. I think the completion file needs a lot of adjustments.

@tgamblin tgamblin removed this from the v0.12.0 milestone May 28, 2019
@adamjstewart
Copy link
Member

@Falkor I'm going to close this PR as most of the commands and their flags are quite out of date. In the meantime, we've merged #14393 which provides a way to automatically generate most of the tab completion script. If you or anyone else want to submit a new PR to add zsh support, use #14393 as a reference and let me know if you have any questions. It should be as simple as adding a share/spack/zsh/spack-completion.in script and a ZshCompletionWriter in lib/spack/spack/cmd/commands.py.

@Falkor
Copy link
Author

Falkor commented Jan 31, 2020

@adamjstewart sure, no problem and thx for the last guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants