Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: _expand completer and hashed dirs
- X-seq: zsh-users 14425
- From: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: _expand completer and hashed dirs
- Date: Mon, 21 Sep 2009 23:34:56 +0200
- In-reply-to: <090921092333.ZM4626@xxxxxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20090921134728.GA10174@xxxxxxxxxxxxxxx> <090921074027.ZM4381@xxxxxxxxxxxxxxxxxxxxxx> <20090921150150.GD10174@xxxxxxxxxxxxxxx> <090921092333.ZM4626@xxxxxxxxxxxxxxxxxxxxxx>
[me in another message]:
>> So, now my completer line reads like this:
>>
>> zstyle ':completion:*' completer _tilde _expand _complete _ignored _approximate
>>
>> And that seems to do what I want so far. :-)
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>:
> I'm glad the _tilde completer fixed you up. Just a word of caution to
> others reading this thread: Not all completion functions can be dropped
> into the completers list that way.
Yeah, and I should have though twice before doing so, too.
Because, after a while, I realizes that I had just screwed up my
entire completion setup. Stuff like 'git <tab>' started to act weird,
because all of a sudden, the _tilde at the start of my configured
completers tried to treat *everything* as a user name or hashed
directory...
So, I sat myself down and wrote up the following (it does something
special if $BUFFER is empty, too; that's an older idea):
[snip]
function ft-complete() {
emulate -L zsh
setopt extendedglob
local action context widget word
if [[ -z ${BUFFER} ]]; then
context=empty
zstyle -s ":zle:ft-complete:${context}" action action || action=empty
zstyle -s ":zle:ft-complete:${context}" widget widget || widget=complete-word
case ${action} in
dot-slash-complete)
BUFFER='./'
CURSOR=2
zle ${widget} -w
;;
empty)
;;
*)
zle ${widget} -w
;;
esac
return 0
fi
word=${LBUFFER##* }
if [[ ${word} == \~* ]] ; then
context=tilde
zstyle -s ":zle:ft-complete:${context}" widget widget || widget=complete-word
zle ${widget} -w
return 0
fi
context=default
zstyle -s ":zle:ft-complete:${context}" widget widget || widget=complete-word
zle ${widget} -w
return 0
}
zle -N ft-complete
[snap]
And then I do this for configuration:
[snip]
zle -C ft-complete-tilde complete-word _generic
zstyle ':completion:ft-complete-tilde:*' completer _tilde _expand _complete _ignored _approximate
zstyle ':zle:ft-complete:tilde' widget ft-complete-tilde
[snap]
My main completer style now is this again:
zstyle ':completion:*' completer _expand _complete _ignored _approximate
This seems to work rather nicely. Without screwing everything up in
the process. :-)
I just thought, I'd let people know before they waste time on trying
out my previous stupidities.
Regards, Frank
Messages sorted by:
Reverse Date,
Date,
Thread,
Author