zsh-workers
 help / color / mirror / code / Atom feed
* File completion with git ls-files
@ 2024-01-07 18:05 Jörg Sommer
  2024-01-07 18:46 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Jörg Sommer @ 2024-01-07 18:05 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 566 bytes --]

Hi,

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`. Because that's most of the time in a
git repo, the usage of `git ls-files` would be useful. Does Zsh provide
anything to do this?

Regards Jörg

-- 
Erfahrung heißt gar nichts. Man kann seine Sache auch 35 Jahre schlecht
machen.
                                            (Kurt Tucholsky)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 269 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: File completion with git ls-files
  2024-01-07 18:05 File completion with git ls-files Jörg Sommer
@ 2024-01-07 18:46 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2024-01-07 18:46 UTC (permalink / raw)
  To: Jörg Sommer; +Cc: zsh-workers

On Sun, Jan 7, 2024 at 10:05 AM Jörg Sommer <joerg@jo-so.de> 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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-07 18:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-07 18:05 File completion with git ls-files Jörg Sommer
2024-01-07 18:46 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).