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

Re: help for writing GNU stow completion



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