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

[solved] Re: _gnu_generic for aliases



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 02.06.2016 07:30, Bart Schaefer wrote:
> On May 19, 10:50am, Paul Seyfert wrote:
> }
> } I crosschecked that also
> } 
> }        compdef _gnu_generic fancyalias
> } 
> } does not result in any suggestions. My understanding is that the
> } _gnu_generic function does not know about the fancyalias / I cannot use
> } the fancyalias inside the _gnu_generic function.
> } 
> } Is there a way to make _gnu_generic work for aliases?
> 
> Have you tried "setopt complete_aliases" ?

Yes,
I created a small test setup attached:
put "testme.sh" in /tmp/ start zsh with

NORMALPROMPT > zsh -f
defaultprompt > source testrc
defaultprompt > /tmp/testme.sh -<TAB><TAB>

works fine

defaultprompt > fancy -<TAB><TAB><TAB>

nothing.

> Unfortunately it's not easily possible to have it both ways, that is, to
> treat an alias as something you can "compdef" and ALSO have the alias be
> expanded to use the completion for the command it eventually becomes.
> 
> This might work a lot of the time:
> 
> setopt complete_aliases
> _expand_alias_and_complete() {
>   if [[ -o complete_aliases && -n $aliases[$words[1]] ]]; then
>     words[1]=( $aliases[$words[1]] )
>     _complete
>   else
>     return 1
>   fi
> }
> zstyle ':completion:*' completer _complete __expand_alias_and_complete

I have that block commented out in testrc. Once I include it, it works!

> 
> Needs tweaking based on the rest of your current "completer" style, but
> hopefully you get the idea.
> 

So far it seems to work as-is when enabeling all other completion
settings (I didn't put all in testrc).

Thanks!
Paul

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJXUAiCAAoJEPOmP9OjPXmroU8P/20/9V+MZVTYUzEfN8V+G/rG
4XyFcWKVSUTlKV2dnSjnUzk4W1+9nOLphakU5ytd8vcDjg9iyNYi7gQ1tombg+2q
kKtgizmdW08wn4IroDDdO2CQ2tx5C87y9GSw5/QI9YS/b9+0W2R8APTpHthuj4si
UwOSIXkGkIrYVSYBcYZjrW4LJarO6gDyUVZg4XKEunjLwLYbKALDGSKdBc8ewUcI
wiYeXiYGyn79wa+VjzGCOG80/uA9TJKjJG6pCbMvDyMVUH/DoUoWR4GKBWivOz3s
I6HHUcL4E8JHKucbckobiBNPxkx6Ei7c2o/hrT1kWPJrv3VQXnqfe6/yzgJzyjhM
zVFhAyZkqxPUV7cB4WXrMi6jHR7ZXB61PVnp6IncIAYxU1qvQiumy9tpDe8sdc8U
y0hSFzqbeI3fdabZvjX3Zmww91iBB8Iyhg7TCEKA7Dkgr04whAAcJvOeXsesLYf4
tHigU8g7VZWOBMV7TnxxJKxCiPTEd+uAv7OHJ7qUIjxDh1lX0+DbOfxY0dP5O9Xc
mz2/YbJzf13bKMw0RHXMwuI8uUGofNXDvBZy9Zr2ayPzBMXMmGRwV4paBPXdWrGw
1PC7eNad1Tm+cwpixRNU+2O5KW3EpOBAG57WSOQLpg2Td3DwBCAb/EJ40GA8soY7
+zFlbtfuZBNX8ULtRQk5
=d2KE
-----END PGP SIGNATURE-----

Attachment: testme.sh
Description: application/shellscript

autoload -U compinit
compinit

setopt +o bashautolist
setopt +o listambiguous
setopt +o autolist

zstyle ':completion:*:default' menu select=0
zstyle ':completion:*:default' compstate last_prompt=1

alias "fancy"=". /tmp/testme.sh"

setopt complete_aliases

compdef _gnu_generic testme.sh
compdef _gnu_generic fancy

# Messages/warnings format
zstyle ':completion:*:descriptions' format $'%{\e[0;33m%}%d:%{\e[0m%}'
zstyle ':completion:*:messages' format $'%{\e[0;31m%}%d%{\e[0m%}'
zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for: %d%{\e[0m%}'
zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'

#setopt complete_aliases
#_expand_alias_and_complete() {
#  if [[ -o complete_aliases && -n $aliases[$words[1]] ]]; then
#    words[1]=( $aliases[$words[1]] )
#    _complete
#  else
#    return 1
#  fi
#}
#zstyle ':completion:*' completer _complete _expand_alias_and_complete


setopt NO_BEEP


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