apple / swift-argument-parser

Straightforward, type-safe argument parsing for Swift
Apache License 2.0
3.33k stars 319 forks source link

[Bash completion]: Respects .file() extensions, uses _filedir #590

Closed gwynne closed 11 months ago

gwynne commented 1 year ago

This PR implements two TODOs left over in the Bash completion script generator code:

  1. CompletionKind.file(extensions:) did not actually honor the extensions array. It now does so.
  2. CompletionKind.file(extensions:) and .directory now both preferentially invoke the _filedir shell function from bash-completion (v1 for Bash 3.2 & v2 for Bash 4.2+), if it is available in the shell environment at the time, falling back on compgen if it is not.

Note: I could not find any open issues referring to these concerns.

Checklist

rauhul commented 1 year ago

@swift-ci please test

gwynne commented 1 year ago

@rauhul I have to be honest; this is my first time tinkering with Bash completion 😅. Here are the references I used in coming up with this:

rauhul commented 11 months ago

@swift-ci please test

rauhul commented 11 months ago

@gwynne it looks like some tests need to be updated:

             if declare -F _filedir >/dev/null; then
               _filedir 'txt'
               _filedir 'md'
               _filedir 'TXT'
               _filedir 'MD'
+              _filedir -d
             else
gwynne commented 11 months ago

@gwynne it looks like some tests need to be updated:

Whoops, sorry! Incoming momentarily 😅

rauhul commented 11 months ago

@swift-ci please test