zsh-users
 help / color / mirror / code / Atom feed
* completion of filenames
@ 2019-12-10 16:17 ` Ray Andrews
  2019-12-10 16:30   ` Peter Stephenson
  0 siblings, 1 reply; 10+ messages in thread
From: Ray Andrews @ 2019-12-10 16:17 UTC (permalink / raw)
  To: Zsh Users

As I have it now TAB only completes filenames after some leading 
command.  If I hit TAB at the beginning of a line it seems to want to 
find commands.  Can I have filename completion active right from the 
start?  Reason being that if I have a suffix alias defined then of 
course all I need is the filename.  I'm terrified to play with it since 
one can break something and only find out latter that expansion no 
longer works in months beginning with 'A'  or some other disaster.  Man, 
such power there, if only there was some way for mortals to understand it.


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

* Re: completion of filenames
  2019-12-10 16:17 ` completion of filenames Ray Andrews
@ 2019-12-10 16:30   ` Peter Stephenson
  2019-12-10 16:59     ` Ray Andrews
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Stephenson @ 2019-12-10 16:30 UTC (permalink / raw)
  To: zsh-users

On Tue, 2019-12-10 at 08:17 -0800, Ray Andrews wrote:
> As I have it now TAB only completes filenames after some leading 
> command.  If I hit TAB at the beginning of a line it seems to want to 
> find commands.  Can I have filename completion active right from the 
> start?  Reason being that if I have a suffix alias defined then of 
> course all I need is the filename.  I'm terrified to play with it since 
> one can break something and only find out latter that expansion no 
> longer works in months beginning with 'A'  or some other disaster.  Man, 
> such power there, if only there was some way for mortals to understand it.

Suffix aliases are already handled.  So if it's a file in the current directory,
you should find typing ./<tab> completes files with a suffix alias defined.

pws


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

* Re: completion of filenames
  2019-12-10 16:30   ` Peter Stephenson
@ 2019-12-10 16:59     ` Ray Andrews
  2019-12-10 17:16       ` Peter Stephenson
  2019-12-13 15:59       ` Ray Andrews
  0 siblings, 2 replies; 10+ messages in thread
From: Ray Andrews @ 2019-12-10 16:59 UTC (permalink / raw)
  To: zsh-users

On 2019-12-10 8:30 a.m., Peter Stephenson wrote:
>
> Suffix aliases are already handled.  So if it's a file in the current directory,
> you should find typing ./<tab> completes files with a suffix alias defined.
>
> pws
>
Doesn't work.  This could be something I've botched up myself. Here's 
what I think is relevant:


    zstyle ':completion:*' completer _expand _complete _files

    #Tab completion should be case-insensitive.
    # Original: zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
    zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}'
    'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
    zstyle ':completion:*' auto-description 'specify: %d'
    zstyle ':completion:*' format 'Completing %d'
    zstyle ':completion:*' group-name ''
    zstyle ':completion:*' list-colors ''
    zstyle ':completion:*' list-prompt %SAt %p: Hit TAB 'for more', or
    the char to insert%s
    ###zstyle ':completion:*' menu select=2
    ### zstyle ':completion:*' menu select=long
    zstyle ':completion:*' select-prompt %SScrolling active: current
    selection at %p%s
    zstyle ':completion:*' use-compctl false
    zstyle ':completion:*' verbose true

    zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
    zstyle ':completion:*:match:*' original only
    zstyle ':completion:*:approximate:*' max-errors 1 numeric
    zstyle ':completion:*:expand:*' tag-order all-expansions
    # cd not select parent dir:
    zstyle ':completion:*:cd:*' ignore-parents parent pwd


... I think water-bedding can happen with this stuff, you fix one issue 
and create another, so previous tinkerings with completion might have 
caused this.  Myself I'd like it as plain vanilla as it could probably 
be, just complete files all the time, every time, in the current 
directory, the less 'helpfulness' the better.  Cool what 's available, 
but I'd like to build up from the basics.

BTW, just to bitch:

     zstyle ':completion:*' completer _expand _complete _files

When you see that in any font that is not fixed width,  you can't hardly 
tell that 'completer_expand' is different from 'completer _expand'  ... 
the space is easy to miss.  Not that there's much that could be done 
about that now.



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

* Re: completion of filenames
  2019-12-10 16:59     ` Ray Andrews
@ 2019-12-10 17:16       ` Peter Stephenson
  2019-12-10 17:45         ` Ray Andrews
  2019-12-13 15:59       ` Ray Andrews
  1 sibling, 1 reply; 10+ messages in thread
From: Peter Stephenson @ 2019-12-10 17:16 UTC (permalink / raw)
  To: zsh-users

On Tue, 2019-12-10 at 08:59 -0800, Ray Andrews wrote:
> On 2019-12-10 8:30 a.m., Peter Stephenson wrote:
> > 
> > 
> > Suffix aliases are already handled.  So if it's a file in the current directory,
> > you should find typing ./<tab> completes files with a suffix alias defined.
> > 
> > pws
> > 
> Doesn't work.  This could be something I've botched up myself.

Try ^x h and you should see something like (warning: these are long
lines I've not attempted to wrap myself so anything could happen):

tags in context :completion::complete:-command-::
    commands executables builtins functions aliases suffix-aliases reserved-words jobs parameters parameters  (_command_names _autocd) 
    commands                                                                                                  (_path_commands _command_names _autocd) 
    globbed-files                                                                                             (_files _command_names _autocd)                  
    directories                                                                                               (_files _command_names _autocd) 
    all-files                                                                                                 (_files _command_names _autocd) 
    jobs                                                                                                      (_jobs _command_names _autocd) 
    parameters                                                                                                (_parameters _command_names _autocd)

The "suffix-aliases" is obviously relevant here.  As you can see it's
handled by _command_names.  (Well, OK, it might be handled by _autocd
but it isn't.)  If you look in there you'll see it's calling
_suffix_alias_files.  I don't see any obvious styles to get in the way.

pws



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

* Re: completion of filenames
  2019-12-10 17:16       ` Peter Stephenson
@ 2019-12-10 17:45         ` Ray Andrews
  0 siblings, 0 replies; 10+ messages in thread
From: Ray Andrews @ 2019-12-10 17:45 UTC (permalink / raw)
  To: zsh-users

On 2019-12-10 9:16 a.m., Peter Stephenson wrote:
>
>   
>> Doesn't work.  This could be something I've botched up myself.
> Try ^x h and you should see something like (warning: these are long
 > Ctrl x + h < did nothing at all.  Like no keystrokes were even entered.

But I'd like completion even if there are no suffix aliases, just plain 
vanilla completion after whatever keystrokes are typed, just as it is 
now but it only works after there's a command typed first. So command or 
no command, just complete filenames and never ever complete commands.  
I'm expecting this would be a simplification of some of the stuff I posted.


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

* Re: completion of filenames
  2019-12-10 16:59     ` Ray Andrews
  2019-12-10 17:16       ` Peter Stephenson
@ 2019-12-13 15:59       ` Ray Andrews
  2019-12-13 16:24         ` Peter Stephenson
  1 sibling, 1 reply; 10+ messages in thread
From: Ray Andrews @ 2019-12-13 15:59 UTC (permalink / raw)
  To: zsh-users

On 2019-12-10 8:59 a.m., Ray Andrews wrote:
> On 2019-12-10 8:30 a.m., Peter Stephenson wrote:
>>
>> Suffix aliases are already handled.  So if it's a file in the current 
>> directory,
>> you should find typing ./<tab> completes files with a suffix alias 
>> defined.
>>
>> pws
>>
> Doesn't work.  This could be something I've botched up myself. Here's 
> what I think is relevant:
>
If no one has any ideas about this, I'm tempted to try to tinker with it 
myself.  Where is 'expand-or-complete' defined?  The string shows up 
dozens of times but I can't find the widget definition. Or, isn't there 
a file somewhere that defines the proper completions for a given 
command?  Yeah, I saw it once but can't remember where it is.  Anyway, 
supposing that I hid that file?  If it can't do any of those match-ups 
between a  command and it's valid completions, might it not just give up 
and complete the filenames anyway?  Or, just make a sort of 'universal' 
command or nul command that always completes on filenames.  Dunno,  but 
it seems that simply bypassing the initial search for a command should 
be doable.  What I do now is type a one letter command that's a function 
equivalent to 'edit', then however many letters to start the filename, 
then hit TAB to complete on filenames, then go to the beginning of the 
line, erase the single letter command, and voila, I have my completed 
filename. Perhaps that operation can be made into a widget?  I found a 
few custom widgets on the web but none that do any such thing, but I'd 
bet it can be done.  The customizations that are on offer are mind 
boggling, but in my case it's the simple thing that's hard to do.





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

* Re: completion of filenames
  2019-12-13 15:59       ` Ray Andrews
@ 2019-12-13 16:24         ` Peter Stephenson
  2019-12-13 17:06           ` Ray Andrews
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Stephenson @ 2019-12-13 16:24 UTC (permalink / raw)
  To: zsh-users

On Fri, 2019-12-13 at 07:59 -0800, Ray Andrews wrote:
> On 2019-12-10 8:59 a.m., Ray Andrews wrote:
> > 
> > On 2019-12-10 8:30 a.m., Peter Stephenson wrote:
> > > 
> > > 
> > > Suffix aliases are already handled.  So if it's a file in the current 
> > > directory,
> > > you should find typing ./<tab> completes files with a suffix alias 
> > > defined.
> > > 
> > > pws
> > > 
> > Doesn't work.  This could be something I've botched up myself. Here's 
> > what I think is relevant:
> > 
> If no one has any ideas about this, I'm tempted to try to tinker with it 
> myself.

[Haven't be been here before...?]

Well, you're welcome to do that, of course, but I can't help thinking
you're shooting yourself in the foot.  The system is designed to work
out of the box; while you can make it do other things, obviously that
implies you need some understanding of how it works before you can build
it up yourself.  Your questions don't tend to suggest that's currently
the case.  Background reading (such as Oliver's chapters in From Bash To
Z Shell) and studying the documentation and the shell code itself are
the first steps to getting there.  Questions here that are going to get
useful answers are probably going to be along the lines of "I read about
X but I don't understand Y" rather than "I don't know what to do but
maybe it's got something to do with Z".  (This is supposed to be
practical --- what I think people will respond to --- not normative ---
I'm not telling you to shut up.)

If you're trying to get completion for suffix aliases going, the normal
way to do this would be to assure yourself they work with a vanilla set
up, then see what configuration of yours is stopping it working.  In my
experience, this is generally more effective that telling people that
what you've currently got doesn't work.

pws


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

* Re: completion of filenames
  2019-12-13 16:24         ` Peter Stephenson
@ 2019-12-13 17:06           ` Ray Andrews
  2019-12-13 19:46             ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Ray Andrews @ 2019-12-13 17:06 UTC (permalink / raw)
  To: zsh-users

On 2019-12-13 8:24 a.m., Peter Stephenson wrote:
> Well, you're welcome to do that, of course, but I can't help thinking
> you're shooting yourself in the foot.
I'll be quite prepared to abandon the idea if I get into trouble. Learn 
by doing tho.

> The system is designed to work
> out of the box; while you can make it do other things, obviously that
> implies you need some understanding of how it works before you can build
> it up yourself.  Your questions don't tend to suggest that's currently
> the case.  Background reading (such as Oliver's chapters in From Bash To
> Z Shell) and studying the documentation and the shell code itself are
> the first steps to getting there.
The completion documentation is overwhelming.  It would be a year of 
study to
understand it.  Without hints I have no chance.  If there is some 
tractable way of
getting what I'd like, that's great, if not, that's ok.  Bart and Dana 
recently showed
me how to complete local files even if the command finds no acceptable 
matches,
so what I'm asking for is sorta an expansion of that idea.

> If you're trying to get completion for suffix aliases going, the normal
> way to do this would be to assure yourself they work with a vanilla set
> up,

Yeah, that would be 90% of it, and since it should work, a forensic 
might be the way to
go, but for now  I'm still pursuing the possibility that any filename 
completion from the
beginning of a line might be doable.  If not then just as you say.

> then see what configuration of yours is stopping it working.  In my
> experience, this is generally more effective that telling people that
> what you've currently got doesn't work.
Well, I'd not say 'doesn't work' (except for suffix aliases) , it seems 
to be designed to
complete after a command.  If it can be tweaked to not require a command 
that's great.
But I must say, given what *can* be done, which is astonishing, asking 
for plain vanilla
completion without reference to a command would not seem like asking for 
the moon.
I'd expect it to  be simply a matter of skipping over the 'find command' 
part of completion.
Or not.  Anyway for now I don't even know where to look.




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

* Re: completion of filenames
  2019-12-13 17:06           ` Ray Andrews
@ 2019-12-13 19:46             ` Bart Schaefer
  2019-12-13 21:10               ` Ray Andrews
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2019-12-13 19:46 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Fri, Dec 13, 2019 at 9:07 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> Or not.  Anyway for now I don't even know where to look.

Let's take this all the way back to the beginning for a moment ...

On Tue, Dec 10, 2019 at 8:19 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> As I have it now TAB only completes filenames after some leading
> command.  If I hit TAB at the beginning of a line it seems to want to
> find commands.  Can I have filename completion active right from the
> start?

When there is nothing at all on the command line, completion starts
out in the special "-command-" context.  If you start from "zsh -f"
and load the completion system (compinit) and then type ^x h (as
previously suggested by PWS -- note, you have to let go of the ctrl
key before hitting h) you will find this (apologies for any extraneous
line wrapping):

%
tags in context :completion::complete:-command-::
    commands builtins functions aliases suffix-aliases reserved-words
jobs parameters parameters  (_command_names _autocd)
    commands
                           (_path_commands _path_commands
_command_names _autocd)
    jobs
                           (_jobs _command_names _autocd)
    parameters
                           (_parameters _command_names _autocd)

You'll notice that "files" are not in that description anywhere.

If we add your "zstyle ':completion:*' completer _expand _complete
_files" setting:

%
tags in context :completion::complete:-command-::
    commands builtins functions aliases suffix-aliases reserved-words
jobs parameters parameters  (_command_names _autocd)
    commands
                           (_path_commands _command_names _autocd)
    jobs
                           (_jobs _command_names _autocd)
    parameters
                           (_parameters _command_names _autocd)
tags in context :completion::files:::
    globbed-files  (_files)

Now we have files, but they're still going to be tried only after all
the more specific context has failed to locate anything.  If you want
files to be tried along with all of those other options, you need to
put _files BEFORE _complete in the zstyle, and if you want that to
happen only at an empty prompt, you need to use the specific -command-
context.

zstyle :completion::complete:-command-:: completer _expand _files _complete
zstyle :completion::complete:-command-:: insert-tab false

Note that when you form a list of completers, the implication is that
if an earlier entry in the list finds ANY possible completion, then
the later entries will not be tried.  So at an empty prompt you are
going to get either the default stuff from _complete, or the local
files from _files, depending on which order those appear in the style.
If you want both all the time, a different formulation would be
needed.

You've got one more issue, I think, based on your subsequent question:

> Where is 'expand-or-complete' defined?

You shouldn't be using both expand-or-complete and the _expand
completer.  If you invoke expand-or-complete, it's going to try to do
expansion on the word and if that succeeds it will never proceed into
attempting completion.  To use _expand, you should be re-binding the
TAB key:

bindkey "^I" complete-word

Usually compinit will take care of this for you, but only if the
zstyle definitions appear in your .zshrc (et al) BEFORE you invoke
compinit.  This is in the doc:

       To  initialize  the system, the function compinit should be in a direc-
       tory mentioned  in  the  fpath  parameter  ...  If completion styles (see
       below) are set up  to  perform  expansion  as  well  as  completion  by
       default,  and the TAB key is bound to expand-or-complete, compinit will
       rebind it to complete-word; this is necessary to use the  correct  form
       of expansion.

Does any of this help with your situation?

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

* Re: completion of filenames
  2019-12-13 19:46             ` Bart Schaefer
@ 2019-12-13 21:10               ` Ray Andrews
  0 siblings, 0 replies; 10+ messages in thread
From: Ray Andrews @ 2019-12-13 21:10 UTC (permalink / raw)
  To: zsh-users

On 2019-12-13 11:46 a.m., Bart Schaefer wrote:

It's more than my tiny brain can really understand Bart, however:

> You've got one more issue, I think, based on your subsequent question:
>
>> Where is 'expand-or-complete' defined?
> You shouldn't be using both expand-or-complete and the _expand
> completer.
I was under the impression that the TAB key called expand-or-complete 
and that this somehow
tweaked itself via the 'zstyle .....' lines.

>    If you invoke expand-or-complete, it's going to try to do
> expansion on the word and if that succeeds it will never proceed into
> attempting completion.  To use _expand, you should be re-binding the
> TAB key:
>
> bindkey "^I" complete-word
>
> Usually compinit will take care of this for you, but only if the
> zstyle definitions appear in your .zshrc (et al) BEFORE you invoke
> compinit.  This is in the doc:
>
>         To  initialize  the system, the function compinit should be in a direc-
>         tory mentioned  in  the  fpath  parameter  ...  If completion styles (see
>         below) are set up  to  perform  expansion  as  well  as  completion  by
>         default,  and the TAB key is bound to expand-or-complete, compinit will
>         rebind it to complete-word; this is necessary to use the  correct  form
>         of expansion.
>
> Does any of this help with your situation?
All possible combinations of the above have not yet been tested, however 
as I have it now:

     zstyle ':completion:*' completer _files _expand _complete 
#('_files' first as you suggest).

      autoload -U compinit && compinit -d $ZSHBOOT/zcompdump
This had been *above* the 'styles', moving it below the 'styles' as you 
indicate seems to have worked :-)
What is puzzling is that your previous help with my 'styles' was 
effective even though 'autoload ...'  was above it.

     # This is the default for TAB:
     #bindkey  '^I' expand-or-complete
     #bindkey '^I' complete word             #(tried but didn't work 
*apart* from the above and seems not needed anyway so TAB is default.

So, pending further advice or tinkerings, It is exactly as I want: empty 
or partial command line is first completed with local files.
I guess this is a cultural issue -- if one is accustomed to the normal 
function then you wouldn't want it any other way and this could
be a last remaining vestige of my DOS-think, but I can't imagine 
completion working on anything other than files myself, seeing commands
pop up really bothers me.

Thanks again Bart.



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

end of thread, other threads:[~2019-12-13 21:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20191210161919epcas1p2c60b547299b6425434345c4f26071643@epcas1p2.samsung.com>
2019-12-10 16:17 ` completion of filenames Ray Andrews
2019-12-10 16:30   ` Peter Stephenson
2019-12-10 16:59     ` Ray Andrews
2019-12-10 17:16       ` Peter Stephenson
2019-12-10 17:45         ` Ray Andrews
2019-12-13 15:59       ` Ray Andrews
2019-12-13 16:24         ` Peter Stephenson
2019-12-13 17:06           ` Ray Andrews
2019-12-13 19:46             ` Bart Schaefer
2019-12-13 21:10               ` Ray Andrews

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