zsh-users
 help / color / mirror / code / Atom feed
* complete as some other sub command
@ 2024-11-04 16:42 Pier Paolo Grassi
  2024-11-04 16:59 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Pier Paolo Grassi @ 2024-11-04 16:42 UTC (permalink / raw)
  To: Zsh-Users List

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

Hello, is it possible to make a function to inherit the completion contest
of another sub command? in my case i would like to make the function gd
complete as it was "git diff"
thanks in advance

Pier Paolo Grassi

[-- Attachment #2: Type: text/html, Size: 461 bytes --]

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

* Re: complete as some other sub command
  2024-11-04 16:42 complete as some other sub command Pier Paolo Grassi
@ 2024-11-04 16:59 ` Peter Stephenson
  2024-11-04 17:14   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2024-11-04 16:59 UTC (permalink / raw)
  To: Zsh-Users List

> On 04/11/2024 16:42 GMT Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
> 
> 
> Hello, is it possible to make a function to inherit the completion contest of another sub command? in my case i would like to make the function gd complete as it was "git diff"

The simple way is

autoload -X _git   # fails if _git is already loaded, harmless
compdef _git-diff gd

Others may be able to think of gotchas requiring something a bit
more sophisticated.

pws


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

* Re: complete as some other sub command
  2024-11-04 16:59 ` Peter Stephenson
@ 2024-11-04 17:14   ` Bart Schaefer
  2024-11-05 11:57     ` Pier Paolo Grassi
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2024-11-04 17:14 UTC (permalink / raw)
  To: Zsh-Users List

On Mon, Nov 4, 2024 at 8:59 AM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
>
> Others may be able to think of gotchas requiring something a bit
> more sophisticated.

There's the "as if" function posted a few days ago to zsh-workers --
haven't tried it myself.

compdef '_as_if git diff' gd

diff --git a/Completion/Base/Utility/_as_if b/Completion/Base/Utility/_as_if
new file mode 100644
index 000000000..84777ee32
--- /dev/null
+++ b/Completion/Base/Utility/_as_if
@@ -0,0 +1,6 @@
+#autoload
+
+local words=("$words[@]") CURRENT=$CURRENT
+words[1]=("$@")
+(( CURRENT += $# - 1 ))
+_normal


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

* Re: complete as some other sub command
  2024-11-04 17:14   ` Bart Schaefer
@ 2024-11-05 11:57     ` Pier Paolo Grassi
  0 siblings, 0 replies; 4+ messages in thread
From: Pier Paolo Grassi @ 2024-11-05 11:57 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh-Users List

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

that worked, thanks

Pier Paolo Grassi


Il giorno lun 4 nov 2024 alle ore 18:15 Bart Schaefer <
schaefer@brasslantern.com> ha scritto:

> On Mon, Nov 4, 2024 at 8:59 AM Peter Stephenson
> <p.w.stephenson@ntlworld.com> wrote:
> >
> > Others may be able to think of gotchas requiring something a bit
> > more sophisticated.
>
> There's the "as if" function posted a few days ago to zsh-workers --
> haven't tried it myself.
>
> compdef '_as_if git diff' gd
>
> diff --git a/Completion/Base/Utility/_as_if
> b/Completion/Base/Utility/_as_if
> new file mode 100644
> index 000000000..84777ee32
> --- /dev/null
> +++ b/Completion/Base/Utility/_as_if
> @@ -0,0 +1,6 @@
> +#autoload
> +
> +local words=("$words[@]") CURRENT=$CURRENT
> +words[1]=("$@")
> +(( CURRENT += $# - 1 ))
> +_normal
>
>

[-- Attachment #2: Type: text/html, Size: 1477 bytes --]

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

end of thread, other threads:[~2024-11-05 11:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-04 16:42 complete as some other sub command Pier Paolo Grassi
2024-11-04 16:59 ` Peter Stephenson
2024-11-04 17:14   ` Bart Schaefer
2024-11-05 11:57     ` Pier Paolo Grassi

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).