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

Bash completion #18

Closed
jgroom33 opened this issue Jul 19, 2019 · 5 comments
Closed

Bash completion #18

jgroom33 opened this issue Jul 19, 2019 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jgroom33
Copy link

Add bash auto completion that parses the markdown file and provides a list of commands (headings) that can be executed
Related to #17

@jacobdeichert
Copy link
Owner

I think this is definitely helpful.. i would also use this. I wonder if zsh and fish shell completions can also be added.

This is not very high on my todo list, but if someone wants to tackle this I would love that.

Ideally it would be as simple as possible and require no changes to mask itself. I imagine it's not too hard for bash/zsh/fish to grep a maskfile.md's headings for commands.

@jacobdeichert jacobdeichert added enhancement New feature or request help wanted Extra attention is needed labels Jul 21, 2019
@jgroom33
Copy link
Author

jgroom33 commented Jul 23, 2019

create a file with contents below and then source it

#/usr/bin/env bash
_mask_completions()
{
  if [ "${#COMP_WORDS[@]}" != "2" ]; then
    return
  fi
  local suggestions=($(compgen -W "$(sed -n '/^```/,/^```/ !p' < maskfile.md | grep \#\# | sed 's/## //')" -- "${COMP_WORDS[1]}"))

  if [ "${#suggestions[@]}" == "1" ]; then
    local number=$(echo ${suggestions[0]/%\ */})
    COMPREPLY=("$number")
  else
    COMPREPLY=("${suggestions[@]}")
  fi
}

complete -F _mask_completions mask

or, if you are trusting:

source /dev/stdin <<< "$(curl https://gist.githubusercontent.com/jgroom33/516283800c4679b6771bc6303ba9610d/raw/fd68678fb122142a4fb4dafe77701ece6a5d4c3c/mask-completion)"

@jacobdeichert
Copy link
Owner

Looks interesting 👍

I'll try this out in the next few days or on the weekend!

@jacobdeichert
Copy link
Owner

Decided to postpone the decision on incorporating bash/zsh/fish/etc shell completion into mask until at least clap v3 is released. At that point, we can reconsider if adding completion script generation into mask makes sense or not.

In the mean time, I'm happy to link to community-supplied completion scripts from the README. If anyone has completion scripts they feel like sharing, please make a PR that links to your completion script gist or repo! :)

Going to close this issue as jgroom33 has supplied a script above that people may be using.

@jacobdeichert
Copy link
Owner

Just a heads up, I'll be publishing a new mask update soon with #85 merged. I hope that exposing the maskfile structure as json can be helpful for generating autocomplete commands in other environments.

On top of this, mask-parser is now a thing. It's a helper lib to parse the maskfile.md format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants