BTS

Issue564

Title support command-not-found within grml's zsh on request?
Priority feature Status resolved
Superseder Nosy List ft, mika
Assigned To ft Topics configs, zsh

Created on 2008-10-27.11:56:23 by mika, last changed 2009-04-04.10:31:04 by ft.

Messages
msg2125 (view) Author: ft Date: 2009-04-04.10:31:01
We believe that your issue has been closed by the upload of
Version 0.3.66 of grml-etc-core from Frank Terbeck <ft@grml.org>.
The explanation is attached below

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Sat, 04 Apr 2009 11:52:50 +0200
Source: grml-etc-core
Binary: grml-etc-core
Architecture: source all
Version: 0.3.66
Distribution: unstable
Urgency: low
Maintainer: Michael Prokop <mika@grml.org>
Changed-By: Frank Terbeck <ft@grml.org>
Description: 
 grml-etc-core - core ecetera files for the grml system
Changes: 
 grml-etc-core (0.3.66) unstable; urgency=low
 .
   * vimrc: only set screen title if the caller explicitly asks for it.
   * zshrc: ask for setting screen title in vim via a wrapper function.
   * zshrc: only compdef commands to _gnu_generic if no native completion
     exists.
   * zshrc: add commit-to-history widget, that allows users to add
     command lines to zsh's history without executing [Closes: issue407]
   * zshrc: add a handler that uses debian's command-not-found package
     if an external command could not be found. [Closes: issue564]
Checksums-Sha1: 
 aa1cde8a633f5e920c7a3f379c17bdcc6a1814a4 873 grml-etc-core_0.3.66.dsc
 5fa626b168a9308a2c3207b14a9a72ab6acb7fd7 109117 grml-etc-core_0.3.66.tar.gz
 42ed7458ffa868d38f68f7eb698dfe0921e61d3b 111632 grml-etc-core_0.3.66_all.deb
Checksums-Sha256: 
 3571db06a08d158c0d656276aecd45073f549bd49d9e0005376d9b4c94b9058f 873 grml-etc-core_0.3.66.dsc
 10c0700f40a7596f9cbb61172c12ac25228b71bf1a85dc79cec071c08dc55a0f 109117 grml-etc-core_0.3.66.tar.gz
 909e639605b737166667459981e4f3d56f8e191bf05a5a7ff3b6492cab832a8d 111632 grml-etc-core_0.3.66_all.deb
Files: 
 ca629360808724690f7abbc0286a710e 873 grml optional grml-etc-core_0.3.66.dsc
 6be50e7b29a2f4e38f3866b92005c466 109117 grml optional grml-etc-core_0.3.66.tar.gz
 e92bd3fdd6cdd7485f9c4b63fee751f1 111632 grml optional grml-etc-core_0.3.66_all.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFJ1zXR2N9T+zficugRArmpAJ9PNzTHmkpD7V2pzbwuriwCw8eFDACePn6p
LfWP0IVKQTODX9iOauDhYIs=
=b7OB
-----END PGP SIGNATURE-----
msg2123 (view) Author: ft Date: 2009-04-03.19:31:47
*sigh*

Apparently, zsh has got 'command_not_found_handler()' since version 4.3.5...
See: http://www.zsh.org/mla/workers/2007/msg00592.html

So I've officially wasted an evening on trying to reinvent a wheel,
due to lack of knowledge and too much ignorance as to looking into
the zsh manual. I found that hook only by grepping for '127' in the
zsh source tree.

I could *so* slap myself with an printed out zsh-manual right now...

Anyway - I've just pushed a possible solution into the branch: ft/cnf
Specifically the commit: 6d36a5125cb844027237cb4a358d9c617a0c62c6

Switching status to 'testing'.
msg2122 (view) Author: ft Date: 2009-04-03.18:57:29
When going through 'My Issues' I found this one again...

I'm sorry I haven't got a decent implementation for this.
As Bart Schaefer noted on zsh-users some time ago, best would
probably be to implement this within the accept-line wrapper,
that we are using. I've been at it for ~45 minutes but I
was not able to resolve this in a way that I would be happy with.

In fact, I was quite unhappy with the results I had.

Then I wanted to go at a half-assed hack so that we could at least
close this bug, even if it wasn't perfect. While doing that for
about half an hour, I got so fed up with myself for even considering
something like that, that it caused me to delete my topic branch
that held the code.

Marking as deferred for now.
msg1639 (view) Author: mika Date: 2008-11-04.13:09:02
* Frank Terbeck <bts@bts.grml.org> [20081104 13:56]:

> > >     a) How does that thing get it's data?

> > Via:

> > % file /var/cache/command-not-found/*
> > /var/cache/command-not-found/ftp.de.debian.org_debian_dists_unstable_contrib.db:           GNU dbm 1.x or ndbm database, little endian
> > /var/cache/command-not-found/ftp.de.debian.org_debian_dists_unstable_main.db:              GNU dbm 1.x or ndbm database, little endian
> > /var/cache/command-not-found/ftp.de.debian.org_debian_dists_unstable_non-free.db:          GNU dbm 1.x or ndbm database, little endian
> > /var/cache/command-not-found/www.debian-multimedia.org_dists_sid_main.db:                  GNU dbm 1.x or ndbm database, little endian
> > /var/cache/command-not-found/www.informatik.uni-koeln.de_fai_download_dists_lenny_main.db: GNU dbm 1.x or ndbm database, little endian

> This was, what I was worried about most.
> But okay, if it builds a database and does lookups against it, I can
> see that that's probably not too shabby.

ACK

[...]
> > -> Works at least pretty well and fast on my system.

> Okay then. I'll think of a usable solution.
> Maybe even via an interface that's only in pretty recent zsh versions,
> if that's okay by you (recent as in 'the live-cd ships a version
> recent enough').

Sure, that's fine. :)

regards,
-mika-
msg1638 (view) Author: ft Date: 2008-11-04.12:56:16
Michael Prokop <bts@bts.grml.org>:
[...]
> >     a) How does that thing get it's data?
> 
> Via:
> 
> % file /var/cache/command-not-found/*
> /var/cache/command-not-found/ftp.de.debian.org_debian_dists_unstable_contrib.db:           GNU dbm 1.x or ndbm database, little endian
> /var/cache/command-not-found/ftp.de.debian.org_debian_dists_unstable_main.db:              GNU dbm 1.x or ndbm database, little endian
> /var/cache/command-not-found/ftp.de.debian.org_debian_dists_unstable_non-free.db:          GNU dbm 1.x or ndbm database, little endian
> /var/cache/command-not-found/www.debian-multimedia.org_dists_sid_main.db:                  GNU dbm 1.x or ndbm database, little endian
> /var/cache/command-not-found/www.informatik.uni-koeln.de_fai_download_dists_lenny_main.db: GNU dbm 1.x or ndbm database, little endian

This was, what I was worried about most.
But okay, if it builds a database and does lookups against it, I can
see that that's probably not too shabby.

[...]
> >     c) How well does it perform, if it's really accurate?
> 
> % zsh -f
> % source /etc/zsh_command_not_found
> % nautilus
> zsh: command not found: nautilus
> The program 'nautilus' is currently not installed.  To run 'nautilus' please ask your administrator to install the package 'nautilus
> '
> %
> 
> -> Works at least pretty well and fast on my system.

Okay then. I'll think of a usable solution.
Maybe even via an interface that's only in pretty recent zsh versions,
if that's okay by you (recent as in 'the live-cd ships a version
recent enough').

Regards, Frank
msg1637 (view) Author: mika Date: 2008-11-04.12:42:31
[...]
> > function preexec() {
> >         command="${1%% *}"
> > }

> > function precmd() {
> >         (($?)) && [ -n "$command" ] && [ -x /usr/share/command-not-found/command-not-found ] && {
> >                 whence -- "$command" >& /dev/null ||
> >                         /usr/share/command-not-found/command-not-found -- "$command"
> >                 unset command
> >         }
> > }

> Okay, *if* we take a stab at this, I'm writing this from scratch.
> <yoda>This I don't like.</yoda>

Hehe ok :)

> > So when sourcing this file and invoking a command which isn't
> > present it displays which Debian package might provide the command.

> Might? So it's basically just guessing? Or does it actually consult
> the dpkg package database (which would be quite expensive, I think;
> .o( apt-file nautilus | grep bin/ | awk { whatever } )).

Might as in "if the command isn't in any Debian package it can't
help the user".

> > Demonstration (manually invoking
> > /usr/share/command-not-found/command-not-found though here):

> > % /usr/share/command-not-found/command-not-found nautilus
> > The program 'nautilus' is currently not installed.  To run 'nautilus' please ask your administrator to install the package 'nautilus'

> Okay, I get the notion.
> However:
>     a) How does that thing get it's data?

Via:

% file /var/cache/command-not-found/*
/var/cache/command-not-found/ftp.de.debian.org_debian_dists_unstable_contrib.db:           GNU dbm 1.x or ndbm database, little endian
/var/cache/command-not-found/ftp.de.debian.org_debian_dists_unstable_main.db:              GNU dbm 1.x or ndbm database, little endian
/var/cache/command-not-found/ftp.de.debian.org_debian_dists_unstable_non-free.db:          GNU dbm 1.x or ndbm database, little endian
/var/cache/command-not-found/www.debian-multimedia.org_dists_sid_main.db:                  GNU dbm 1.x or ndbm database, little endian
/var/cache/command-not-found/www.informatik.uni-koeln.de_fai_download_dists_lenny_main.db: GNU dbm 1.x or ndbm database, little endian

AFAICS.

>     b) How accurate are its predictions?

Very accurate AFAICS.

>     c) How well does it perform, if it's really accurate?

% zsh -f
% source /etc/zsh_command_not_found
% nautilus
zsh: command not found: nautilus
The program 'nautilus' is currently not installed.  To run 'nautilus' please ask your administrator to install the package 'nautilus
'
%

-> Works at least pretty well and fast on my system.

regards,
-mika-
msg1636 (view) Author: ft Date: 2008-11-04.12:26:47
Michael Prokop <bts@bts.grml.org>:
> Michael Prokop <mika@grml.org> added the comment:
> * Frank Terbeck <bts@bts.grml.org> [20081027 22:32]:
> 
> > I actually meant. How does command-not-found work? :-)
[...]

Back to this one...

[...]
> function preexec() {
>         command="${1%% *}"
> }
> 
> function precmd() {
>         (($?)) && [ -n "$command" ] && [ -x /usr/share/command-not-found/command-not-found ] && {
>                 whence -- "$command" >& /dev/null ||
>                         /usr/share/command-not-found/command-not-found -- "$command"
>                 unset command
>         }
> }

Okay, *if* we take a stab at this, I'm writing this from scratch.
<yoda>This I don't like.</yoda>

> So when sourcing this file and invoking a command which isn't
> present it displays which Debian package might provide the command.

Might? So it's basically just guessing? Or does it actually consult
the dpkg package database (which would be quite expensive, I think;
.o( apt-file nautilus | grep bin/ | awk { whatever } )).

> Demonstration (manually invoking
> /usr/share/command-not-found/command-not-found though here):
> 
> % /usr/share/command-not-found/command-not-found nautilus
> The program 'nautilus' is currently not installed.  To run 'nautilus' please ask your administrator to install the package 'nautilus'

Okay, I get the notion.
However:
    a) How does that thing get it's data?
    b) How accurate are its predictions?
    c) How well does it perform, if it's really accurate?

Regards, Frank
msg1631 (view) Author: mika Date: 2008-10-27.21:38:57
* Frank Terbeck <bts@bts.grml.org> [20081027 22:32]:

> I actually meant. How does command-not-found work? :-)

Ah, sorry. :)

,---- [ /etc/zsh_command_not_found ]
| # (c) Zygmunt Krynicki 2007,
| # Licensed under GPL, see COPYING for the whole text
| #
| # This script will look-up command in the database and suggest
| # installation of packages available from the repository
|
| function preexec() {
|         command="${1%% *}"
| }
|
| function precmd() {
|         (($?)) && [ -n "$command" ] && [ -x /usr/share/command-not-found/command-not-found ] && {
|                 whence -- "$command" >& /dev/null ||
|                         /usr/share/command-not-found/command-not-found -- "$command"
|                 unset command
|         }
| }
`----

So when sourcing this file and invoking a command which isn't
present it displays which Debian package might provide the command.

Demonstration (manually invoking
/usr/share/command-not-found/command-not-found though here):

% /usr/share/command-not-found/command-not-found nautilus
The program 'nautilus' is currently not installed.  To run 'nautilus' please ask your administrator to install the package 'nautilus
'

regards,
-mika-
msg1630 (view) Author: ft Date: 2008-10-27.21:32:20
Michael Prokop <bts@bts.grml.org>:
> Michael Prokop <mika@grml.org> added the comment:
> * Frank Terbeck [20081027 21:19]:
> > Michael Prokop:
> > > See http://packages.debian.org/sid/main/command-not-found
> 
> > > Frank, would it be possible to support this feature in grml's zsh 
> > > configuration? It shouldn't clash with current preexec() precmd() and should be 
> > > enabled just on request. Any chance to get that? :)
> 
> > Well, how would I have to envisage such a feature to work?
> > Example "workflow"?
> 
> Hmmmm, maybe when the user is executing 'command-not-found' it
> should set up the command-not-found feature?

Heh.

I actually meant. How does command-not-found work? :-)

Regards, Frank
msg1629 (view) Author: mika Date: 2008-10-27.21:24:56
* Frank Terbeck [20081027 21:19]:
> Michael Prokop:

> > See http://packages.debian.org/sid/main/command-not-found

> > Frank, would it be possible to support this feature in grml's zsh 
> > configuration? It shouldn't clash with current preexec() precmd() and should be 
> > enabled just on request. Any chance to get that? :)

> Well, how would I have to envisage such a feature to work?
> Example "workflow"?

Hmmmm, maybe when the user is executing 'command-not-found' it
should set up the command-not-found feature?

regards,
-mika-
msg1628 (view) Author: ft Date: 2008-10-27.20:19:22
Michael Prokop <bts@bts.grml.org>:
> See http://packages.debian.org/sid/main/command-not-found
> 
> Frank, would it be possible to support this feature in grml's zsh 
> configuration? It shouldn't clash with current preexec() precmd() and should be 
> enabled just on request. Any chance to get that? :)

Well, how would I have to envisage such a feature to work?
Example "workflow"?

Regards, Frank
msg1627 (view) Author: mika Date: 2008-10-27.11:56:23
See http://packages.debian.org/sid/main/command-not-found

Frank, would it be possible to support this feature in grml's zsh 
configuration? It shouldn't clash with current preexec() precmd() and should be 
enabled just on request. Any chance to get that? :)

thx && regards,
-mika-
History
Date User Action Args
2009-04-04 10:31:04ftsetstatus: fixed-in-git -> resolved
nosy: mika, ft
messages: + msg2125
2009-04-04 09:55:37ftsetstatus: testing -> fixed-in-git
nosy: mika, ft
2009-04-03 19:31:48ftsetstatus: deferred -> testing
nosy: mika, ft
messages: + msg2123
2009-04-03 18:57:33ftsetstatus: chatting -> deferred
nosy: mika, ft
messages: + msg2122
2008-11-04 13:09:02mikasetnosy: mika, ft
messages: + msg1639
2008-11-04 12:56:16ftsetnosy: mika, ft
messages: + msg1638
2008-11-04 12:42:32mikasetnosy: mika, ft
messages: + msg1637
2008-11-04 12:26:49ftsetnosy: mika, ft
messages: + msg1636
2008-10-27 21:38:58mikasetnosy: mika, ft
messages: + msg1631
2008-10-27 21:32:21ftsetnosy: mika, ft
messages: + msg1630
2008-10-27 21:24:58mikasetnosy: mika, ft
messages: + msg1629
2008-10-27 20:19:24ftsetstatus: unread -> chatting
nosy: mika, ft
messages: + msg1628
2008-10-27 11:56:23mikacreate