Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: help for writing GNU stow completion
- X-seq: zsh-workers 44694
- From: Aurélien <orel_jf@xxxxxxxx>
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>, dana <dana@xxxxxxx>
- Subject: Re: help for writing GNU stow completion
- Date: Tue, 20 Aug 2019 19:45:47 +0200
- Autocrypt: addr=orel_jf@xxxxxxxx; prefer-encrypt=mutual; keydata= mQINBFnrjSUBEADGm1wZcrhssIdITo581Nen6VlNeO/Yh28fmlYhKtSME53emVhg7TYqu/cM eJV1SxRE/fZCx7yNX9IARCjCuhvXRrsLoxbuRHlybALDfByv7OJBUJhd6JU/Trubx68fLs+W fKXqRqNN4Pobezgg8/vA9LU/aWhj46LCOcFD0MpxfnxW56IzunV443xlYUGdDehdBEosUNlf 9KuJ24d5PpgzNHe9bB6LVLZvVoO164aAoeKLifC8MtV11JOk43wsZkM1ZCNjt3GU2qFv4/Jo 6M9Wo6oLvuvnh1xKrCJa/zh3Kx3IQ1CbNjXHLna5TF7Zx6KLUUNaLnFzymdMjnzvnLyH1GvA N7yKcyG5uKaqZGq2v8h20fcp/ag/SoZOhC9TMELBGlSuwoTV0qXX/uYaraxAaCwBIENL8tKp Kqo5LX4AgTKHq60C6rJnjTUSX68RbvSEJacoIzVXMM1wpGOmp0fH4KqHsaN9pTOQ4vuU+K7f ptTqmWiBZXTqRCmIo11AC3Po50EeeYdtjB+OMfvNLSk5q226/gR9p5oBc58B0zeG9Kt1nl33 zG01spC20rv7awXhw5WMeGR14mZ5X5UShb5hIyA3bSyErGuvN+J0HCCN3WdH3ZEO2Ols20az QCZwZwcwju/06ZDGAJzoTxqMeOIFHWwPDrcbXpbinR8EacwTkQARAQABtCRBdXLDqWxpZW4g T0xJVklFUiA8b3JlbF9qZkB5YWhvby5mcj6JAlQEEwEIAD4WIQRpjQYRG7yMFUmG5I9INEIz GKktMAUCWeuNJQIbAwUJA8JnAAULCQgHAgYVCAk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imm+qQgbDX/mL8nLAWcZbaDX1cBZhv2zSRB6RqF3LoJJe+u3Q1lcPfkjtn6
- Cc: zsh-users <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.fr; s=s2048; t=1566323150; bh=avz1Awd0LsVrywWaAdiPRFYnZ0NsEBxR5ZJHV+OXbIc=; h=To:Cc:References:From:Subject:Date:In-Reply-To:From:Subject; b=cOkW+vL6lf+0pJcCtLo/M0T02KQRwyIJTa98n++yczlIPbfXSNdPui5tbjEmvIsusFUy+Ca6eN9+2PUezd7/d9Ll5VFZjiPprfAj2bERDu/LPT66Ekn6BrbdtSqv9MozKlpBiujyvnIvH0gqxNR0mltRVMsQJyYqxMzhNKOMWKNy4e4j2/5to/D12646ipar2/Ahr34QMUKwk2IBxGGb3H7sTkmPGOwosj1qN13MXjFbdswaP+H3Y0m9IlL3MOg+Qdq2ZeciHnGNJksBEn6o7o4NomjKelo17dOCAAhJODiNPB9Qh/s8ulDK+tSsNTA5XzfupZlgRKv52NjvyIKwXQ==
- In-reply-to: <0618d7fc-5334-4e51-829a-8684a81744c1@www.fastmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Openpgp: preference=signencrypt
- References: <1e5195bb-3126-8d0c-8a6a-1f5a5fd2a6c0@yahoo.fr> <BAE67462-BF39-481A-BCD6-DE288FE6CC92@dana.is> <d30637f3-cbbb-8b93-35f2-421a1a99e1dc@yahoo.fr> <0618d7fc-5334-4e51-829a-8684a81744c1@www.fastmail.com>
Le 17/08/2019 ?? 19:53, Daniel Shahaf a ??crit??:
> [moving to -workers@ since it's about an outstanding PR]
>
> Aur??lien wrote on Sat, 17 Aug 2019 07:51 +00:00:
>> local stow_dir
>> local -a stow_pkg_list
>>
>> eval set -A stow_dir $1
>> [[ -n $stow_dir ]] && stow_pkg_list=( $stow_dir/*(-/N:t) )
>>
>> if [[ ${#stow_pkg_list} -gt 0 ]]; then
>> _values -C "packages from $stow_dir" ${stow_pkg_list[@]}
>> else
>> _message "no packages found in $stow_dir"
>> fi
>>
>> and the completion of parameters such as'$HOME' or'~/' works well !
>>
>> I pushed my modifications on github. Thank you for the answers :-)
>
> Sorry, but I have to object to the PR as it stands. As I said, using
> ??eval $1?? causes expressions on the command line to be evaluated
> _when completion is attempted_. To me, that breaks the principle of
> least surprise, and could lead to unexpected and undesired results.
>
Okay, I understand the idea, so I tried to change the function to this:
__stow_complete_packages() {
local stow_dir=${(Q)1}
local -a stow_pkg_list=( $stow_dir/*(-/N:t) )
if [[ ${#stow_pkg_list} -gt 0 ]]; then
_values -C "packages from $stow_dir" ${stow_pkg_list[@]}
else
_message "no packages found in $stow_dir"
fi
}
But now if I do ?? stow --dir=$HOME/.dotfiles<TAB> ??, I get ????no packages
found in $HOME/.dotfiles????. Maybe I missed something???
> I would strongly prefer another solution, or to be corrected on my
> interpretation that this violates least surprise.
>
> Also, I don't think it's ideal to have ??foo --opt=$ARG<TAB>?? work and
> ??bar --opt=$ARG<TAB>?? not work.
>
To remove any ambiguity, I want to complete the stow packages
stow --dir $HOME/.dotfiles <TAB>
_packages from /home/username/.dotfiles_
git myrepos nano nvim ranger rofi [???]
And not the directories
stow --dir $HOME/.dotfiles/<TAB>
_directory_
git myrepos nano nvim ranger rofi [???]
My initial goal was to get a completion of the same type as what
password-store offers (see: line 127 at
https://git.zx2c4.com/password-store/tree/src/completion/pass.zsh-completion).
This is where the ????find???? in the first version of the script comes from.
Naively, as a user, when I do ????stow --dir $HOME/.dotfiles <TAB>???? and
the directory in question contains many subdirectories, if the
completion does not offer any packages, it is surprising.
Now, due to my limited experience in writing completion for zsh, I don't
know what would be the least bad of the solutions.
Thank you for your time.
--
Aur??lien
Messages sorted by:
Reverse Date,
Date,
Thread,
Author