From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22164 invoked from network); 28 Aug 2020 08:21:40 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 28 Aug 2020 08:21:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=K3DMFREKWRy/tvOBIqvwMWGPhuuRX/WbtfJ75Jm/eVM=; b=jDWQDDHcSfxq3+lUurZe8AICuA 626ICAcHRIX+yLu9LT0PTSAINYyjn7IK28fEnX/JQjYOL+qKmNiNKpufj1QfEVxaX+6PUB/hpPjGl /v400gSX6yI0+mz8M4UnTGGMU9KRB/mgD6TfEEI8IWJ0RBldxOpwNk3aCdA7JKxKxPwz/SR65crtw YEYKRYC37B0ZOGLQVb1bgA2IakgTgGdL4Y3SjXSkgzwf4uqX/VXNCxYK+tplnS70S7FJIdZE+YHts DUNhqtR6Z89WsLp9cZdivismWbsS6iaDcJOF6zX0KajTh2YVgmyMl5HkRHopOgdkNsHoRvuPxBYjg UlSq5SVw==; Received: from authenticated user by zero.zsh.org with local id 1kBZdg-000ChJ-7S; Fri, 28 Aug 2020 08:21:36 +0000 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 Received: from mail-io1-f54.google.com ([209.85.166.54]:39192) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kBZdN-000CYg-IM; Fri, 28 Aug 2020 08:21:19 +0000 Received: by mail-io1-f54.google.com with SMTP id h10so400636ioq.6 for ; Fri, 28 Aug 2020 01:21:17 -0700 (PDT) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=K3DMFREKWRy/tvOBIqvwMWGPhuuRX/WbtfJ75Jm/eVM=; b=eYYCYOSbmMsXk7W/YcCdhTEhSyj+R9UPgfc8ykWLnAqSPtx49Sr1tHW5PWqEa83tBt CvD6JzAytp8H8jB+5NxhFwbAfudDDwpjK3EPvieHopKntbXKqIXg/wzrQ1yYyItDCupY PNO7qewCsrWaCOyPQI5WYp1oIF8s+CSmtTkX7X/CYmqgSInpA6xufHpdHN+FE8oEZk0c lRz9J9NU4fYAIItcXTbqJhis39wu5Ho8HSDSbWa1RKmwKxt+adUZkC+FddZMQwA4Sgm1 1GQz98US+bFzkGyb5Fma6Pjpw7/1Q+WDWMy+94fMAOwO0XZhSViKcmMqUrsIYjmzOXnl t4IQ== X-Gm-Message-State: AOAM530BmHVIbXDe83trA6oywjrdkFo+Bbd5kujLSg2imusrD5VhwMtK 7CETNocPu9sFlNbNZns5lVfKWP8/E4LQXJHyqoc= X-Google-Smtp-Source: ABdhPJzpRykxGZZs7C+zKZjLQPjZpqVmUgqrpC3Jbo5Z/Ty41PWYSI2UBkZ6AFhkR+G1K7ePCmtbvwMHpRryfsr9BiI= X-Received: by 2002:a02:820b:: with SMTP id o11mr175826jag.136.1598602875315; Fri, 28 Aug 2020 01:21:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Fri, 28 Aug 2020 10:21:04 +0200 Message-ID: Subject: Re: Minor details of command_not_found_handler To: Bart Schaefer Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 47346 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On Fri, Aug 28, 2020 at 7:41 AM Bart Schaefer 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.