zsh-users
 help / color / mirror / code / Atom feed
* Tab completion of multiple files using curly braces
@ 2009-02-20 14:14 Allan Caffee
  2009-02-20 17:10 ` Andrey Borzenkov
  2009-02-21  4:46 ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Allan Caffee @ 2009-02-20 14:14 UTC (permalink / raw)
  To: Zsh Users

With my current setup tab completion of a word with curly braces in it
(e.g. foo{bar,biz}) Zsh expands it.  For example:

% diff ./{old,new}/obnoxiously_long_f<TAB>

% diff ./old/obnoxiously_long_f ./new/obnoxiously_long_f

I'd really like to have the shell avoid expansion and instead look for
possible completions using the union of the file names under all
expansions.  For example:

% diff ./{old,new}/obnoxiously_long_f<TAB>

% diff ./{old,new}/obnoxiously_long_file_name.
  obnoxiously_long_file_name.c obnoxiously_long_file_name.h

where obnoxiously_long_file_name.c and obnoxiously_long_file_name.h
exist in both old and new.  I imagine it wouldn't be too difficult to
write a completion function for this and I already have the completer
set up to favor completion over expansion.  Is this completion function
already implemented?


~Allan


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

* Re: Tab completion of multiple files using curly braces
  2009-02-20 14:14 Tab completion of multiple files using curly braces Allan Caffee
@ 2009-02-20 17:10 ` Andrey Borzenkov
  2009-02-20 18:30   ` Allan Caffee
  2009-02-21  4:46 ` Bart Schaefer
  1 sibling, 1 reply; 4+ messages in thread
From: Andrey Borzenkov @ 2009-02-20 17:10 UTC (permalink / raw)
  To: zsh-users; +Cc: Allan Caffee

[-- Attachment #1: Type: text/plain, Size: 378 bytes --]

On 20 of February 2009 17:14:52 Allan Caffee wrote:
> With my current setup tab completion of a word with curly braces in
> it (e.g. foo{bar,biz}) Zsh expands it.  For example:
>
> % diff ./{old,new}/obnoxiously_long_f<TAB>
>
> % diff ./old/obnoxiously_long_f ./new/obnoxiously_long_f
>

Hmm ... with my setup it does not complete anything at all.

Could you show "zstyle -L"?


[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: Tab completion of multiple files using curly braces
  2009-02-20 17:10 ` Andrey Borzenkov
@ 2009-02-20 18:30   ` Allan Caffee
  0 siblings, 0 replies; 4+ messages in thread
From: Allan Caffee @ 2009-02-20 18:30 UTC (permalink / raw)
  To: zsh-users

On Fri, Feb 20, 2009 at 12:10 PM, Andrey Borzenkov <arvidjaar@gmail.com> wrote:
> Hmm ... with my setup it does not complete anything at all.
>
> Could you show "zstyle -L"?

The first line is the one that enables expansion.  Notice that
expansion is only tried after all other methods have failed.

zstyle ':completion:*' completer _oldlist _complete _match _expand _prefix
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
zstyle ':completion:*:make:*' ignored-patterns '*-local' '*-am'
'*-recursive' am--refresh '*-generic' '*%*'
zstyle ':completion:*' list-colors 'no=00' 'fi=00' 'di=01;34'
'ln=01;36' 'pi=40;33' 'so=01;35' 'do=01;35' 'bd=40;33;01'
'cd=40;33;01' 'or=40;31;01' 'su=37;41' 'sg=30;43' 'tw=30;42'
'ow=34;42' 'st=37;44' 'ex=01;32' '*.tar=01;31' '*.tgz=01;31'
'*.arj=01;31' '*.taz=01;31' '*.lzh=01;31' '*.zip=01;31' '*.z=01;31'
'*.Z=01;31' '*.gz=01;31' '*.bz2=01;31' '*.deb=01;31' '*.rpm=01;31'
'*.jar=01;31' '*.jpg=01;35' '*.jpeg=01;35' '*.gif=01;35' '*.bmp=01;35'
'*.pbm=01;35' '*.pgm=01;35' '*.ppm=01;35' '*.tga=01;35' '*.xbm=01;35'
'*.xpm=01;35' '*.tif=01;35' '*.tiff=01;35' '*.png=01;35' '*.mov=01;35'
'*.mpg=01;35' '*.mpeg=01;35' '*.avi=01;35' '*.fli=01;35' '*.gl=01;35'
'*.dl=01;35' '*.xcf=01;35' '*.xwd=01;35' '*.flac=01;35' '*.mp3=01;35'
'*.mpc=01;35' '*.ogg=01;35' '*.wav=01;35'
zstyle ':completion:*' menu 'select=2'
zstyle ':completion:*:expand:*' add-space true


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

* Re: Tab completion of multiple files using curly braces
  2009-02-20 14:14 Tab completion of multiple files using curly braces Allan Caffee
  2009-02-20 17:10 ` Andrey Borzenkov
@ 2009-02-21  4:46 ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2009-02-21  4:46 UTC (permalink / raw)
  To: Zsh Users

On Feb 20,  9:14am, Allan Caffee wrote:
}
} With my current setup tab completion of a word with curly braces in it
} (e.g. foo{bar,biz}) Zsh expands it.  For example:
} 
} % diff ./{old,new}/obnoxiously_long_f<TAB>
} 
} I'd really like to have the shell avoid expansion and instead look for
} possible completions using the union of the file names under all
} expansions.

This is unfortunately quite difficult.  Completion is really designed
to resolve one argument to one matching string; what you're in effect
asking for here is to simultaneously complete two arguments at once.
This doesn't even work with glob completion; e.g. if instead you try

% diff ./(old|new)/ob<TAB>

or even

% diff ./*/ob<TAB>

it'll first insist that you resolve the pattern part down to one or
the other of old or new before proceeding to complete path tails.

You can't do this by adding another completer like _expand or _match.
Those are invoked at too high a level.  To make this work you'd have
to hijack file completion somewhere down in the guts of _path_files,
and pass "{old,new}' directly to compadd -Q so the brace expression
(or pattern in the glob case) becomes part of the completion result;
and *then* when completing the later portions of the path I believe
you'd need to do the comparisons yourself to assure that the full
result really does match all branches of the brace expression.

However, you might almost be able to get what you want from the
_expand completer by simply appending a "*" to the argument before
you complete, and then accept the all-expansions group of matches.
E.g.:

% diff ./{old,new}/obnoxiously_long_f*<TAB>

should offer something like (among other stuff):

Completing all expansions
./old/obnoxiously_long_file_name.c ./new/obnoxiously_long_file_name.c

and it wouldn't be so difficult to whip up something to automatically
insert that "*" before attempting the expansion.


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

end of thread, other threads:[~2009-02-21  4:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-20 14:14 Tab completion of multiple files using curly braces Allan Caffee
2009-02-20 17:10 ` Andrey Borzenkov
2009-02-20 18:30   ` Allan Caffee
2009-02-21  4:46 ` Bart Schaefer

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