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

Investigate bash auto-completion #20

Open
brianp opened this issue Jul 17, 2016 · 2 comments
Open

Investigate bash auto-completion #20

brianp opened this issue Jul 17, 2016 · 2 comments

Comments

@brianp
Copy link
Owner

brianp commented Jul 17, 2016

We want two types of auto complete:

  • Auto complete muxed commands (only new)
  • Auto complete project names
@brianp brianp added this to the v1.0.0 milestone Nov 3, 2016
@brianp brianp removed this from the v1.0.0 milestone Nov 25, 2019
@brianp
Copy link
Owner Author

brianp commented Dec 13, 2019

#/usr/bin/env bash
_muxed_completions()
{

  if [ "$COMP_CWORD" -eq 1 ]; then
    local commands="$(compgen -W "new edit snapshot" "${COMP_WORDS[1]}")"
    local projects="$(compgen -W "$(echo $(ls ~/.muxed/))" "${COMP_WORDS[1]}")"
    COMPREPLY=( $commands $projects )
  elif [ "$COMP_CWORD" -eq 2 ]; then
    local projects="$(compgen -W "$(echo $(ls ~/.muxed/))" "${COMP_WORDS[2]}")"
    COMPREPLY=( $projects )
  fi
}

complete -F _muxed_completions muxed

A simple first pass.

It'll auto complete subcommands, and projects available in the default directory only.

Expand it to autocomplete projects but stripping the .yml (extension) in the filename.
Have it complete in custom directories.

@coreyja
Copy link
Contributor

coreyja commented Dec 6, 2020

With the ls subcommand this has gotten a bit simpler. Here is my current config

#/usr/bin/env bash
_muxed_completions()
{

  if [ "$COMP_CWORD" -eq 1 ]; then
    local commands="$(compgen -W "new edit snapshot load" "${COMP_WORDS[1]}")"
    local projects="$(compgen -W "$(muxed ls)" "${COMP_WORDS[1]}")"
    COMPREPLY=( $commands $projects )
  elif [ "$COMP_CWORD" -eq 2 ]; then
    local projects="$(compgen -W "$(muxed ls)" "${COMP_WORDS[2]}")"
    COMPREPLY=( $projects )
  fi
}

complete -F _muxed_completions muxed

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

No branches or pull requests

2 participants