zsh-users
 help / color / mirror / code / Atom feed
From: Aurélien <orel_jf@yahoo.fr>
To: dana <dana@dana.is>
Cc: zsh-users <zsh-users@zsh.org>
Subject: Re: help for writing GNU stow completion
Date: Sat, 17 Aug 2019 09:48:45 +0200	[thread overview]
Message-ID: <d30637f3-cbbb-8b93-35f2-421a1a99e1dc@yahoo.fr> (raw)
In-Reply-To: <BAE67462-BF39-481A-BCD6-DE288FE6CC92@dana.is>

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

      parent reply	other threads:[~2019-08-17  7:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06 17:04 Aurélien
2019-08-15 23:36 ` dana
2019-08-16  1:28   ` Daniel Shahaf
2019-08-16  1:54     ` dana
2019-08-17  7:48   ` Aurélien [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d30637f3-cbbb-8b93-35f2-421a1a99e1dc@yahoo.fr \
    --to=orel_jf@yahoo.fr \
    --cc=dana@dana.is \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).