bashConfiguration top-level property

  1. @visibleForTesting
ShellCompletionConfiguration bashConfiguration
final

Implementation

@visibleForTesting
final bashConfiguration = ShellCompletionConfiguration._(
  shell: SystemShell.bash,
  shellRCFile: '~/.bash_profile',
  sourceLineTemplate: (String scriptPath) {
    return '[ -f $scriptPath ] && . $scriptPath || true';
  },
  scriptTemplate: (String rootCommand) {
    // Completion script for bash.
    //
    // Based on https://github.com/mklabs/tabtab/blob/master/lib/scripts/bash.sh
    return '''
if type complete &>/dev/null; then
  _${rootCommand}_completion () {
    local words cword
    if type _get_comp_words_by_ref &>/dev/null; then
      _get_comp_words_by_ref -n = -n @ -n : -w words -i cword
    else
      cword="\$COMP_CWORD"
      words=("\${COMP_WORDS[@]}")
    fi
    local si="\$IFS"
    IFS=\$'\n' COMPREPLY=(\$(COMP_CWORD="\$cword" \\
                           COMP_LINE="\$COMP_LINE" \\
                           COMP_POINT="\$COMP_POINT" \\
                           $rootCommand completion -- "\${words[@]}" \\
                           2>/dev/null)) || return \$?
    IFS="\$si"
    if type __ltrim_colon_completions &>/dev/null; then
      __ltrim_colon_completions "\${words[cword]}"
    fi
  }
  complete -o default -F _${rootCommand}_completion $rootCommand
fi
''';
  },
);