muxed icon indicating copy to clipboard operation
muxed copied to clipboard

Investigate bash auto-completion

Open brianp opened this issue 9 years ago • 2 comments

We want two types of auto complete:

  • Auto complete muxed commands (only new)
  • Auto complete project names

brianp avatar Jul 17 '16 06:07 brianp

#/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.

brianp avatar Dec 13 '19 23:12 brianp

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

coreyja avatar Dec 06 '20 21:12 coreyja