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

Re: help for writing GNU stow completion



Le 16/08/2019 ?? 01:36, dana a ??crit??:
> You can use the (Q) expansion flag to strip quotes, which is a semi-common
> thing in completion functions when they need to take user input from the
> command line, but there's no flag for anything fancier, and most functions
> don't seem to bother with it. But if you wanted to, something like this is
> probably the best way...?
> 
>   local -a stow_pkg_list
>   eval set -A stow_pkg_list $1
>   [[ -n $stow_pkg_list ]] && stow_pkg_list=( $stow_pkg_list/*(-/N:t) )
> 
> It's not perfectly accurate, though; for example, because of how _arguments
> breaks up optargs, this would treat `--dir=~/foo` and `--dir ~/foo` the same,
> even though the tilde would not actually be expanded before passing it to stow
> in the former case (unless magic_equal_subst was enabled)
> 

Knowing that this option only accepts one value and after a few tests,
it seems that 'eval' is the right solution, . My function now looks like
this:

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

-- 
Aur??lien



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