bash-completion for arbitrary commands

To use the completion for ssh for any command ssh * /etc/bash_completion:

. /usr/share/bash-completion/bash_completion
# set up dynamic completion loading
_completion_loader()
{
  local compdir=./completions
  [[ $BASH_SOURCE == */* ]] && compdir="${BASH_SOURCE%/*}/completions"
  # Try basename.
  . "$compdir/${1##*/}" &>/dev/null && return 124
  # Arbitrary ssh command
  [[ $1 =~ .*ssh ]] && . /usr/share/bash-completion/completions/ssh >/dev/null 2>&1 && complete -F _ssh $1 && return 124

    # Need to define *something*, otherwise there will be no completion at all.
  complete -F _minimal "$1" && return 124
} &&
complete -D -F _completion_loader

Note: completion loader was mostly extracted from /usr/share/bash-completion/bashcompletion itself, just the "# Arbitrary ssh command" part was added.

  • Nächstes Thema