DannyBen/completely

View on GitHub
lib/completely/templates/template.erb

Summary

Maintainability
Test Coverage
# <%= "#{command} completion".ljust 56 %> -*- shell-script -*-

# This bash completions script was generated by
# completely (https://github.com/dannyben/completely)
# Modifying it manually is not recommended

<%= function_name %>_filter() {
  local words="$1"
  local cur=${COMP_WORDS[COMP_CWORD]}
  local result=()

  if [[ "${cur:0:1}" == "-" ]]; then
    echo "$words"

  else
    for word in $words; do
      [[ "${word:0:1}" != "-" ]] && result+=("$word")
    done

    echo "${result[*]}"

  fi
}

<%= function_name %>() {
  local cur=${COMP_WORDS[COMP_CWORD]}
  local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
  local compline="${compwords[*]}"

% if ENV['COMPLETELY_DEBUG']
  if [[ -n "$COMPLETELY_DEBUG" ]]; then
    echo "compline: '$compline'" > 'completely-debug.txt'
    echo "cur:      '$cur'" >> 'completely-debug.txt'
  fi

% end
  case "$compline" in
% patterns.each do |pattern|
% next if pattern.empty?
    <%= pattern.case_string %>)
      while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen <%= pattern.compgen %> -- "$cur")
      ;;

% end
  esac
} &&
  complete -F <%= function_name %> <%= command %>

# ex: filetype=sh