Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Minor details of command_not_found_handler
- X-seq: zsh-workers 47346
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Minor details of command_not_found_handler
- Date: Fri, 28 Aug 2020 10:21:04 +0200
- Archived-at: <https://zsh.org/workers/47346>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-08/CAN%3D4vMpszhuF3V5RGgwwUa5tv1GZ9NSOcsKCmmAy__49qtNw%2Bw%40mail.gmail.com>
- Authentication-results: zsh.org; iprev=pass (mail-io1-f54.google.com) smtp.remote-ip=209.85.166.54; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=skipped; arc=none
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=K3DMFREKWRy/tvOBIqvwMWGPhuuRX/WbtfJ75Jm/eVM=; b=quMkC8q4nfej6O7fsV+ncePtDRxzGXNKAwV9J8T6pFmYqhojyWgDe4U65k6RKW6Kwf siPLfM9EIe2IRhPxo8/IQWZMer5On/x7JTK7oZ6RTkAtt8xvrfMZYSIP3ch7nS0zsz4u T+WyyJy18W6QNMuBRLjLijXEz/19CECcr7+I+X6evjK8JIfJ823lgYwuzDf6wW/LJLD2 QAW+g/vszQv9WF31uCK8oIH1YHD1a2lqMWNQKQQNSXppRQZ10Wd0Zd17A8nUe3OhtmYa moewc3Zm9Hg8ldH6UCa4CakOA/5qla5oxeIAT8GOigicgmWYdA2fRmUZUtnzqP87gieF 9lvg==
- In-reply-to: <CAH+w=7aUeoTJFJiEqZYMoa0D6StxTfZGraUYADJYWbuu1uSC4A@mail.gmail.com>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- References: <CAH+w=7aUeoTJFJiEqZYMoa0D6StxTfZGraUYADJYWbuu1uSC4A@mail.gmail.com>
- Sender: zsh-workers-request@xxxxxxx
On Fri, Aug 28, 2020 at 7:41 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> 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.
FWIW, here's how I hook up GNU command-not-found in interactive Zsh:
function command_not_found_handler() {
emulate -L zsh
if (( $#functrace >= 2 )); then
print -ru2 -- "$functrace[1]: command not found: $1"
else
local msg="$(/usr/lib/command-not-found --no-failure-msg -- $1 2>&1)"
if [[ -n $msg ]]; then
print -ru2 -- ${msg#$'\n'}
else
print -ru2 -- "zsh: command not found: $1"
fi
fi
return 127
}
The check for (( $#functrace >= 2 )) is there in order to invoke the
incredibly slow /usr/lib/command-not-found only when mistyping a
command on the command line. It doesn't do exactly that but it's close
enough.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author