zsh-users
 help / color / mirror / code / Atom feed
* completing and hiding some prefixes
@ 2013-08-07 20:14 Daniel
  2013-08-08 19:16 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel @ 2013-08-07 20:14 UTC (permalink / raw)
  To: zsh-users

I have files in ~/foo/. Among them, some are named: fa_abc fa_frog
fa_gag. I want to write completion for a command "fofa", which completes
among these particular files, but omitting the "fa_" prefix. Thus:

  $ fofa [TAB]
  $ fofa abc[TAB]
  $ fofa frog

I tried a few options of compadd, like -p, but it seems I would need to
write a separate function.

It would perhaps be interesting to have something more general, which
can complete for commands on the same pattern, but different
suffix/prefixes.

This is my naive attempt:

#compdef fofa

local cachedir

cachedir=~/foo/
#setopt extendedglob
_arguments '1:foo-cache:_files -W $cachedir  -g "fa_*"'


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: completing and hiding some prefixes
  2013-08-07 20:14 completing and hiding some prefixes Daniel
@ 2013-08-08 19:16 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2013-08-08 19:16 UTC (permalink / raw)
  To: zsh-users

On Wed, 7 Aug 2013 20:14:25 +0000 (UTC)
Daniel <quite@hack.org> wrote:
> I have files in ~/foo/. Among them, some are named: fa_abc fa_frog
> fa_gag. I want to write completion for a command "fofa", which completes
> among these particular files, but omitting the "fa_" prefix. Thus:
> 
>   $ fofa [TAB]
>   $ fofa abc[TAB]
>   $ fofa frog

You need something like this.

pws


#fofa

local cachedir=~/foo expl
local -a files

files=($cachedir/fa_*(:t))
files=(${files##fa_})

_wanted foo-cache expl 'foo cache' compadd -a files


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-08-08 19:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-07 20:14 completing and hiding some prefixes Daniel
2013-08-08 19:16 ` Peter Stephenson

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