Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Minor details of command_not_found_handler



Doc says:
       ... If  the  function wishes to mimic the behaviour of the shell
       when the command is not found, it should print the message `command not
       found:  cmd'  to  standard  error and return status 127.

Except that does not really mimic the behavior.  Interactive shells print e.g.:

zsh: command not found: notacommand

and non-interactive shells add a line number:

zsh:1: command not found: notacommand

This almost does it:

  print -u2 -r -- "${functrace[1]:-$ZSH_ARGZERO}: command not found: $1"
  return 127

The nit being that $functrace[1] for a login shell contains "-zsh"
rather than "zsh", and of course includes the line number whether or
not the shell is interactive.

One thing that the doc fails to mention is that, even when
function_argzero is set, $0 inside command_not_found_handler is the
same as $1 (i.e., the name of the not-found command).  However, %N for
prompt expansion is "command_not_found_handler".




Messages sorted by: Reverse Date, Date, Thread, Author