Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: File completion with git ls-files



On Sun, Jan 7, 2024 at 10:05 AM Jörg Sommer <joerg@xxxxxxxx> wrote:
>
> I am looking for a way to complete the full path to files in a subdirectory
> by its name. I would like to enter `less foo`, hit TAB (or a special short
> cut) and cycle through the list of `dir/subd-1/subd-2/foo…`,
> `dir2/abc/foo…`, `dir2/s1/s2/s3/foo`.

This is more along the lines of a zsh-users question, but something like this:

git-search-complete() {
  local f
  for f in ${(f)"$( git ls-files )"}
  do
    if [[ $f = */* ]]
    then
      compadd -f -P $f:h/ $f:t
    else
      compadd -f $f
    fi
  done
}
zle -C git-search-complete .menu-complete git-search-complete

Then bindkey git-search-complete to your preference.

This could pretty easily be made into an entry in your "completer"
zstyle to be invoked by TAB when nothing is found by earlier
completers.




Messages sorted by: Reverse Date, Date, Thread, Author