zsh-users
 help / color / mirror / code / Atom feed
* default to file completion
@ 2011-12-18 10:11 Miek Gieben
  2011-12-18 13:57 ` Mikael Magnusson
  2011-12-20 19:38 ` gi1242+zsh
  0 siblings, 2 replies; 11+ messages in thread
From: Miek Gieben @ 2011-12-18 10:11 UTC (permalink / raw)
  To: Zsh users

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

Hello,

I've tried searching a bit, but I can not seem to find this specific
problem. I've enablef completion in zsh and now I'm running a program
of my own making (hence unknown to zsh): 'scan'

If I use tab completion the following happens:

    ./scan -zone <TAB>

And nothing gets completed. How can I tell zsh to fallback to filename
completion at that point?

Thanks,

 grtz,

-- 
    Miek

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: default to file completion
  2011-12-18 10:11 default to file completion Miek Gieben
@ 2011-12-18 13:57 ` Mikael Magnusson
  2011-12-18 15:20   ` Miek Gieben
  2011-12-22 23:01   ` Miek Gieben
  2011-12-20 19:38 ` gi1242+zsh
  1 sibling, 2 replies; 11+ messages in thread
From: Mikael Magnusson @ 2011-12-18 13:57 UTC (permalink / raw)
  To: Zsh users

On 18 December 2011 11:11, Miek Gieben <miek@miek.nl> wrote:
> Hello,
>
> I've tried searching a bit, but I can not seem to find this specific
> problem. I've enablef completion in zsh and now I'm running a program
> of my own making (hence unknown to zsh): 'scan'
>
> If I use tab completion the following happens:
>
>    ./scan -zone <TAB>
>
> And nothing gets completed. How can I tell zsh to fallback to filename
> completion at that point?

"scan" is a command that already has completion in zsh (it's part of
mh), but if you don't have mh it won't be able to produce any
completions. To disable a bundled completion, run compdef -d scan
after running compinit.

-- 
Mikael Magnusson


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

* Re: default to file completion
  2011-12-18 13:57 ` Mikael Magnusson
@ 2011-12-18 15:20   ` Miek Gieben
  2011-12-22 23:01   ` Miek Gieben
  1 sibling, 0 replies; 11+ messages in thread
From: Miek Gieben @ 2011-12-18 15:20 UTC (permalink / raw)
  To: zsh-users

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

[ Quoting <mikachu@gmail.com> at 14:57 on Dec 18 in "Re: default to file ..." ]
> "scan" is a command that already has completion in zsh (it's part of
> mh), but if you don't have mh it won't be able to produce any
> completions. To disable a bundled completion, run compdef -d scan
> after running compinit.

Ah, that explains things:

% mv scan 1scan
% ./1scan -zone <TAB> (works)

Thanks for your reply. I'll just rename this command.

 grtz,

-- 
    Miek

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: default to file completion
  2011-12-18 10:11 default to file completion Miek Gieben
  2011-12-18 13:57 ` Mikael Magnusson
@ 2011-12-20 19:38 ` gi1242+zsh
  1 sibling, 0 replies; 11+ messages in thread
From: gi1242+zsh @ 2011-12-20 19:38 UTC (permalink / raw)
  To: Zsh users

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

On Sun, Dec 18, 2011 at 11:11:32AM +0100, Miek Gieben wrote:

> I've tried searching a bit, but I can not seem to find this specific
> problem. I've enablef completion in zsh and now I'm running a program
> of my own making (hence unknown to zsh): 'scan'
> 
> If I use tab completion the following happens:
> 
>     ./scan -zone <TAB>
> 
> And nothing gets completed. How can I tell zsh to fallback to filename
> completion at that point?

Here's an alternative to a case by case disabling of zsh completion, or
renaming commands.

    1. To plain old fall back on filename completion:

	    zstyle ':completion:*' completer _expand _complete _files \
		_correct _approximate

       The important thing above is the "_files" entry. This means if
       expansion or completion fails, it will try filename completion.
       (If that fails too, it will try correction or approximation.)

    2. Define a widgit that just completes files, and bind it to
       something (e.g. <C-X>f, in the example below).

	    zle -C complete-file menu-expand-or-complete _generic
	    zstyle ':completion:complete-file:*' completer _files
	    bindkey -M viins '^Xf'      complete-file
    
       (Change -M viins to -M emacs if you don't use VI keys)

       This allows you to complete files anywhere, on any command, at
       any time, by pressing <C-X>f (i.e. Control X, followed by f).

GI

-- 
100 THINGS I'D DO IF I EVER BECAME AN EVIL OVERLORD
34. I will not turn into a snake. It never helps.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: default to file completion
  2011-12-18 13:57 ` Mikael Magnusson
  2011-12-18 15:20   ` Miek Gieben
@ 2011-12-22 23:01   ` Miek Gieben
  2011-12-22 23:42     ` '$1' indexing Ray Andrews
  2011-12-23 20:45     ` default to file completion Bart Schaefer
  1 sibling, 2 replies; 11+ messages in thread
From: Miek Gieben @ 2011-12-22 23:01 UTC (permalink / raw)
  To: zsh-users

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

[ Quoting <mikachu@gmail.com> at 14:57 on Dec 18 in "Re: default to file ..." ]
> > If I use tab completion the following happens:
> >
> >    ./scan -zone <TAB>
> >
> > And nothing gets completed. How can I tell zsh to fallback to filename
> > completion at that point?
> 
> "scan" is a command that already has completion in zsh (it's part of
> mh), but if you don't have mh it won't be able to produce any
> completions. To disable a bundled completion, run compdef -d scan
> after running compinit.

While watching TV, I thought about this again.

Is there a way to disable the default completion for the
command 'scan' if you start it with './' ?

Or, more general, if you start a command with ./ can you automatically
disable the default completion?

 grtz,

-- 
    Miek

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* '$1' indexing.
  2011-12-22 23:01   ` Miek Gieben
@ 2011-12-22 23:42     ` Ray Andrews
  2011-12-23  0:11       ` Bart Schaefer
  2011-12-23 20:45     ` default to file completion Bart Schaefer
  1 sibling, 1 reply; 11+ messages in thread
From: Ray Andrews @ 2011-12-22 23:42 UTC (permalink / raw)
  To: zsh-users

Hi!

First post.  I thought I'd try zsh given how well spoken about it is. My 
first exercise  has been to try to convert my bash functions to zsh, and 
it has not gone smoothly, but most problems have proved to be solvable.  
But what do you guys think of this:

function z
{
var=$1
echo "var:/${1:0:1}/${1:1:1}/${1:2:1}/"
echo "var:/${var:0:1}/${var:1:1}/${var:2:1}/"

}

$ z abcde

var: /a/a/b/
var: /a/b/c/

Surely the indexing of '$1' is wrong? I can assign the value to 'var' 
and all is well but I don't think I should have to.

Thoughts?


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

* Re: '$1' indexing.
  2011-12-22 23:42     ` '$1' indexing Ray Andrews
@ 2011-12-23  0:11       ` Bart Schaefer
  2011-12-23  2:08         ` Ray Andrews
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2011-12-23  0:11 UTC (permalink / raw)
  To: Ray Andrews, zsh-users

Hmm, you posted exactly this same thing with the subject "bug" on the
20th.  Did you not see the replies?  Yes, it's a bug, and a patch for
it has also been posted.

See http://www.zsh.org/mla/workers/2011/msg01456.html for explanation
and http://www.zsh.org/mla/workers/2011/msg01459.html for patch.


On Dec 22,  3:42pm, Ray Andrews wrote:
} Subject: '$1' indexing.
}
} Hi!
} 
} First post.  I thought I'd try zsh given how well spoken about it is. My 
} first exercise  has been to try to convert my bash functions to zsh, and 
} it has not gone smoothly, but most problems have proved to be solvable.  
} But what do you guys think of this:
} 
} function z
} {
} var=$1
} echo "var:/${1:0:1}/${1:1:1}/${1:2:1}/"
} echo "var:/${var:0:1}/${var:1:1}/${var:2:1}/"
} 
} }
} 
} $ z abcde
} 
} var: /a/a/b/
} var: /a/b/c/
} 
} Surely the indexing of '$1' is wrong? I can assign the value to 'var' 
} and all is well but I don't think I should have to.
} 
} Thoughts?
}-- End of excerpt from Ray Andrews



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

* Re: '$1' indexing.
  2011-12-23  0:11       ` Bart Schaefer
@ 2011-12-23  2:08         ` Ray Andrews
  2011-12-23 20:56           ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Ray Andrews @ 2011-12-23  2:08 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

On 22/12/11 04:11 PM, Bart Schaefer wrote:
> Hmm, you posted exactly this same thing with the subject "bug" on the
> 20th.  Did you not see the replies?  Yes, it's a bug, and a patch for
> it has also been posted.
>
Ooops! I just joined this list today. I forgot about the previous post, 
and I didn't even know if it had been received, let alone answered. I 
did post it on StackOverflow, but that is of course different. Anyway, I 
see your reply and I understand what's going on. I'm too new to this to 
have any strong opinion, but it seems to me that the behavior we see 
would perhaps be good for '$@' where '$0' is implied, but not for an 
explicit '$1'.

Glad to know that the developers are aware of it, thanks.

FWIW it seems to me that zsh has the 'right idea' when it comes to 
string splitting. It's true that converting my bash scripts has involved 
a more laborious coding in zsh (mostly needing to use 'eval'), but that 
is the price to be paid for keeping variables unbroken unless you 
specifically ask for the breakdown into words.

So what is the current state of zsh development? How many workers are 
there? Is zsh ascendant? Is ground being gained against bash?
> See http://www.zsh.org/mla/workers/2011/msg01456.html for explanation
> and http://www.zsh.org/mla/workers/2011/msg01459.html for patch.
>


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

* Re: default to file completion
  2011-12-22 23:01   ` Miek Gieben
  2011-12-22 23:42     ` '$1' indexing Ray Andrews
@ 2011-12-23 20:45     ` Bart Schaefer
  2011-12-25 10:32       ` Miek Gieben
  1 sibling, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2011-12-23 20:45 UTC (permalink / raw)
  To: Miek Gieben, zsh-users

On Dec 23, 12:01am, Miek Gieben wrote:
}
} > >    ./scan -zone <TAB>
} > >
} > > And nothing gets completed. How can I tell zsh to fallback to filename
} > > completion at that point?
} > 
} > "scan" is a command that already has completion in zsh
} 
} Is there a way to disable the default completion for the
} command 'scan' if you start it with './' ?

You can intercept completion pretty early on by providing a compdef for
the special context "-first-".

-first-
     This is tried before any other completion function.  The function
     called may set the _compskip parameter to one of various values:
     all: no further completion is attempted; a string containing the
     substring patterns: no pattern completion functions will be
     called; a string containing default: the function for the
     `-default-' context will not be called, but functions defined for
     commands will [be]

Although it's not documented in the man pages, this can also be done by
redefining the function _first (which by default is a no-op).  Hence:

    _first() {
      if [[ CURRENT -gt 1 && "${words[1]}" = ./* ]];
      then
        _compskip=all
        _files
      fi
    }

There's a much more complicated example as a large comment in the _first
function that is supplied with the shell.


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

* Re: '$1' indexing.
  2011-12-23  2:08         ` Ray Andrews
@ 2011-12-23 20:56           ` Bart Schaefer
  0 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2011-12-23 20:56 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

On Dec 22,  6:08pm, Ray Andrews wrote:
}
} ... I understand what's going on. I'm too new to this to 
} have any strong opinion, but it seems to me that the behavior we see 
} would perhaps be good for '$@' where '$0' is implied, but not for an 
} explicit '$1'.

Yes, that was the intended behavior and that's what the patch implements.
It's already been checked in to the source repository for next release.
 
} FWIW it seems to me that zsh has the 'right idea' when it comes to 
} string splitting. It's true that converting my bash scripts has involved 
} a more laborious coding in zsh (mostly needing to use 'eval')

There are very few places where you ought to need "eval" -- more likely
you should simply have replaced ${var} with ${=var} in those places.

} So what is the current state of zsh development? How many workers are 
} there? Is zsh ascendant? Is ground being gained against bash?

There are three or four people who regularly work on the shell plus a
couple of others who maintain the ports for various linux distributions
and jump in when bugs get filed against their dists.  Beyond that there
are a number of others who contribute sporadically.  We could use some
more regular people; during zsh's most rapid development years we had
several university students working on it, but C is no longer the most-
studied language so that source of energy has faded.

I wouldn't say any particular shell is "gaining ground" at this point,
and none of the developers of any of the shells really looks on it as
a competition anyway.


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

* Re: default to file completion
  2011-12-23 20:45     ` default to file completion Bart Schaefer
@ 2011-12-25 10:32       ` Miek Gieben
  0 siblings, 0 replies; 11+ messages in thread
From: Miek Gieben @ 2011-12-25 10:32 UTC (permalink / raw)
  To: zsh-users

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

[ Quoting <schaefer@brasslantern.com> at 12:45 on Dec 23 in "Re: default to file ..." ]
> Although it's not documented in the man pages, this can also be done by
> redefining the function _first (which by default is a no-op).  Hence:
> 
>     _first() {
>       if [[ CURRENT -gt 1 && "${words[1]}" = ./* ]];
>       then
>         _compskip=all
>         _files
>       fi
>     }
> 
> There's a much more complicated example as a large comment in the _first
> function that is supplied with the shell.

Thanks! Very helpful.

 grtz,

-- 
    Miek

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

end of thread, other threads:[~2011-12-25 10:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-18 10:11 default to file completion Miek Gieben
2011-12-18 13:57 ` Mikael Magnusson
2011-12-18 15:20   ` Miek Gieben
2011-12-22 23:01   ` Miek Gieben
2011-12-22 23:42     ` '$1' indexing Ray Andrews
2011-12-23  0:11       ` Bart Schaefer
2011-12-23  2:08         ` Ray Andrews
2011-12-23 20:56           ` Bart Schaefer
2011-12-23 20:45     ` default to file completion Bart Schaefer
2011-12-25 10:32       ` Miek Gieben
2011-12-20 19:38 ` gi1242+zsh

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