From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27543 invoked by alias); 19 Dec 2016 04:59:44 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22237 Received: (qmail 2590 invoked from network); 19 Dec 2016 04:59:44 -0000 X-Qmail-Scanner-Diagnostics: from mta01.eastlink.ca by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(24.224.136.30):SA:0(-3.8/5.0):. Processed in 1.649614 secs); 19 Dec 2016 04:59:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: rayandrews@eastlink.ca X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.eastlink.ca designates 24.224.136.30 as permitted sender) X-Authority-Analysis: v=2.2 cv=ZvqvEJzG c=1 sm=1 tr=0 a=28Ntk8jg+Dho8ABWn/CRtA==:117 a=28Ntk8jg+Dho8ABWn/CRtA==:17 a=N659UExz7-8A:10 a=0zz_igcFjnVTEyqTW8EA:9 a=pILNOxqGKmIA:10 X-EL-IP-NOAUTH: 24.207.16.108 Subject: Re: trapped in bash To: zsh-users@zsh.org References: <58540944.3030706@eastlink.ca> <20161216215117.GF2023@pug.qqx.org> <58546D36.5050908@eastlink.ca> <161216150556.ZM4016@torch.brasslantern.com> <58559FC0.3080501@eastlink.ca> <161217124354.ZM7815@torch.brasslantern.com> <5855BEF2.6090208__18199.534857604$1482015164$gmane$org@eastlink.ca> <20161218150628.GB9158@fujitsu.shahaf.local2> <5856B133.9010602@eastlink.ca> <20161219003219.GA21509@fujitsu.shahaf.local2> <161218183056.ZM5304@torch.brasslantern.com> From: Ray Andrews Message-id: <9da2ae82-ac3f-6ee3-5452-5a008cf129e7@eastlink.ca> Date: Sun, 18 Dec 2016 20:29:33 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0 MIME-version: 1.0 In-reply-to: <161218183056.ZM5304@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 18/12/16 06:30 PM, Bart Schaefer wrote: > On Dec 19, 12:32am, Daniel Shahaf wrote: > } > } I suppose you could write a command_not_found_handler() function that > } tried to reverse engineer _why_ the command wasn't found - with the > } obvious limitations, e.g., race conditions between the library's > } execution and the handler's. > > I don't think there can be a race here because the handler won't be > invoked if the execve() hasn't already failed. > > Something like this: > > command_not_found_handler () { > local attempt="$1" > if [[ "$1" != /* && ( -o pathdirs || "$1 > " != */* ) ]] > then > emulate zsh -c 'attempt=$^path/$1(N[1])' > fi > if [[ -f $attempt ]] > then > local hashbang > read -u 0 -k 2 hashbang < "$attempt" > case "$hashbang" in > ('#!') print -u2 -- $1\: bad '#!' interpreter ;; > (*) print -u2 failed to load $1 ;; > esac > else > print -u2 -- $1\: no such file in \$PATH > fi > return 127 > } > > Not for me to say, but it seems to me that the simple fact that a file exists or does not exist is simple enough to determine in the tradition of 'whence' or something like that. *Then* we run into issues about executing it *after* the thing has (obviously) been found. Sometimes a command can't be found because it can't be found, that is, the file simply does not exist. Or is that too simple? Anyway I sure like the idea.