bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] command-not-found-handle


From: Ken Irving
Subject: Re: [PATCH] command-not-found-handle
Date: Wed, 9 Apr 2008 13:10:19 -0800
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

On Sun, Apr 04, 2004 at 05:23:36PM +0200, Michael Vogt wrote:
> Dear Friends,

> I attached a small patch that adds a "command-not-found-handle" for
> bash 2.05b.0(1)-release. If a given command is not found and the
> function "command-not-found-handle" is definied, it is called with the
> faild comand as parameter. If it's not defined the behaviour is
> unchanged. 
> 
> Please tell me what you think about the patch and if there is a chance
> for it to get integrated into bash. See [1] for some rational why this
> might be usefull.
> 
> thanks,
>  Michael
> 
> [1] http://www.geocrawler.com/mail/msg.php3?msg_id=2795796&list=342

This patch (or very similar) was accepted into debian's bash some time
ago, though apparently not upstream.  I'm interested in extending this
patch to include the command arguments; currently only the command
string itself is passed to the "hook" function.

In the patch, shell variables f and v are declared, but v is not used;
my guess is that that may have been intended for the argument list, but
for some reason was dropped.  I haven't yet figured out how to make this
work, but will keep trying...

The referenced link [1] to some rational hasn't aged well, and I'd be
interested in seeing any discussions of this feature.

My interest is to "extend" bash to support object oriented commands,
which I currently have to explicitly run through a handler; e.g., to use:

  $ object.do_something args...

instead of:

  $ tob object.do_something args...

where the tob script parses object and method, resolves the method to
some executable via path-like information associated with the object,
and then executes the equivalent of

  $ $class_path/do_something object args...

I think this should be relatively safe, since there are probably few
executables which include a dot in their name.

Finally, I thought it should be possible to find the command line with
arguments under /proc/$pid, but no joy there either; if that was the 
case, the command_not_found_handle function could perhaps reconstruct 
the full command in order to pass to the tob handler.  I'm running debian
stable and unstable systems, e.g.,

  $ uname -a
  Linux hayes 2.6.18-4-686 #1 SMP Wed May 9 23:03:12 UTC 2007 i686 GNU/Linux

Thanks for any thoughts, ridicule, etc., on this.

Ken

> --- execute_cmd.c.orig        2004-04-04 15:40:18.000000000 +0200
> +++ execute_cmd.c     2004-04-04 16:41:33.000000000 +0200
> @@ -3270,8 +3270,23 @@
>  
>        if (command == 0)
>       {
> -       internal_error ("%s: command not found", pathname);
> -       exit (EX_NOTFOUND);   /* Posix.2 says the exit status is 127 */
> +        SHELL_VAR *f, *v;  
> +        WORD_LIST *cmdlist;
> +        WORD_DESC *w;
> +        int fval;
> +        f = find_function ("command-not-found-handle");
> +        if (f == 0) {
> +           internal_error ("%s: command not found", pathname);
> +           exit (EX_NOTFOUND);       /* Posix.2 says the exit status is 127 
> */
> +        }
> +        w = make_word("command-not-found-handle");
> +        cmdlist = make_word_list(w, (WORD_LIST*)NULL);
> +
> +        w = make_word(pathname);
> +        cmdlist->next = make_word_list(w, (WORD_LIST*)NULL);
> +        
> +        fval = execute_shell_function (f, cmdlist);  
> +        exit(fval);
>       }
>  
>        /* Execve expects the command name to be in args[0].  So we

-- 
Ken Irving, address@hidden, http://sourceforge.net/projects/thinobject/
Hi=~/lib/thinob/Try/Hi; mkdir -p $Hi; ln -s /usr/local/lib/thinob $Hi/^
hi=$(tob Try/Hi.tob hi); echo -e '#!/bin/sh\nshift\necho Hello $*!'>$hi
chmod +x $hi; mkdir say; ln -s $Hi say/^; tob say.hi world





reply via email to

[Prev in Thread] Current Thread [Next in Thread]