Re: [PATCH v3 3/3] sparse-checkout: limit tab completion to a single level
- From
Lessley Dennington <lessleydennington@gmail.com>
- Date
- Jan 12, 2022, 23:43 UTC
- Message-ID
- <0e4bb6f1-337e-38b3-75b2-fe11ff8d68b2@gmail.com>
- In-Reply-To
- <aa9ea67180dd10ef8bdf17e8c23694da15828b21.1641841193.git.gitgitgadget@gmail.com>
Show 14 quoted lines
> +__gitcomp_directories ()
> +{
> + local _tmp_dir _tmp_completions
> +
> + # Get the directory of the current token; this differs from dirname
> + # in that it keeps up to the final trailing slash. If no slash found
> + # that's fine too.
> + [[ "$cur" =~ .*/ ]]
> + _tmp_dir=$BASH_REMATCH
> +
> + # Find possible directory completions, adding trailing '/' characters
> + _tmp_completions="$(git ls-tree -d --name-only HEAD $_tmp_dir |
> + sed -e s%$%/%)"
> +I am admittedly unfamiliar with the use of this format in sed expressions (I'm generally more accustomed to '/' instead of '%'). It's definitely working as it should, I'm just not quite sure of how.
> + if [[ -n "$_tmp_completions" ]]; then > + # There were some directory completions, so find ones that > + # start with "$cur", the current token, and put those in COMPREPLY > + local i=0 c IFS=$' \t\n'
Does c need to be declared before the loop?
Show 8 quoted lines
> + for c in $_tmp_completions; do
> + if [[ $c == "$cur"* ]]; then
> + COMPREPLY+=("$c")
> + fi
> + done
> + elif [[ "$cur" =~ /$ ]]; then
> + # No possible further completions any deeper, so assume we're at
> + # a leaf directory and just consider it completeThank you so much for the detailed comments on this change - it made it really easy to parse.
> + __gitcomp_direct_append "$cur "
What's the reason for the trailing space here?
> + fi > +}
Added my review as mentioned in [1].
[1]: https://lore.kernel.org/git/pull.1108.v2.git.1640892413.gitgitgadget@gmail.com/T/#md3da435452988b0366ab4c2ee4bc06df2d17cb36