git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/1] completion: dir-type optargs for am, format-patch

From
Rubén Justo <rjusto@gmail.com>
Date
Feb 29, 2024, 00:04 UTC
Message-ID
<6683f24e-7e56-489d-be2d-8afe1fc38d2b@gmail.com>
In-Reply-To
<CAC4O8c9z4s4fFU6_h6ZRBnDhZyiTp3XR8j0DrARj+1SauLbQEQ@mail.gmail.com>
On Mon, Feb 12, 2024 at 13:52:53 -0900, Britton Kerin wrote:
Show 31 quoted lines
> __git_complete_dir ()
> {
>         local cur_="$cur"
> 
>         while test $# != 0; do
>                 case "$1" in
>                 --cur=*)        cur_="${1##--cur=}" ;;
>                 *)              return 1 ;;
>                 esac
>                 shift
>         done
> 
>         # This rev-parse invocation amounts to a pwd which respects -C options
>         local context_dir=$(__git rev-parse --show-toplevel
> --show-prefix 2>/dev/null | paste -s -d '/' 2>/dev/null)
>         [ -d "$context_dir" ] || return 1
> 
>         compopt -o noquote
> 
>         local IFS=$'\n'
>         local unescaped_candidates=($(cd "$context_dir" 2>/dev/null &&
> compgen -d -S / -- "$cur_"))
>         for ii in "${!unescaped_candidates[@]}"; do
>                 COMPREPLY[$ii]=$(printf "%q" "${unescaped_candidates[$ii]}")
>         done
> }
> 
> This one works for all weird characters that I've tried in bash 5.2 at
> least, and in frameworks that do their own escaping also (e.g.
> ble.sh).  Since your advice so far was so good I thought I'd ask if
> there is anything obvious to you that is still wrong here?
> If not I guess what's left is special code to make it work better with
> old versions of bash.  I'm a little sceptical that this is worth it
> since bash 5 is already 5 years old and it's only completion code
> we're talking about  but I guess it could be done.

I don't think you need to dig too much into old Bash versions. If it works with a recent one, it's a good start.

Have you considered adding some tests to t/t9902-completion.sh?

It is desirable to see some tests at least for __git_complete_dir. Perhaps it would also help you to polish the function.

Sorry for the late response. I just found your message while reviewing the topics in the 'What's cooking'.

Previous: Britton Kerin
Message 6 of 6 in “completion: complete dir-type option args to am, format_patch”
  1. 0/1 completion: complete dir-type option args to am, format_patchBritton Leo Kerin, Jan 7, 2024
  2. 0/1 completion: complete dir-type option args to am, format_patchBritton Leo Kerin, Jan 9, 2024
  3. 1/1 completion: dir-type optargs for am, format-patchBritton Leo Kerin, Jan 9, 2024
  4. Rubén JustoFeb 3, 2024
  5. Britton KerinFeb 13, 2024
  6. Rubén JustoFeb 29, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.