brianp / muxed

Another TMUX project manager
MIT License
59 stars 3 forks source link

Investigate bash auto-completion #20

Open brianp opened 8 years ago

brianp commented 8 years ago

We want two types of auto complete:

brianp commented 4 years ago
#/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 commented 3 years ago

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