From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13341 invoked by alias); 26 Sep 2013 23:36:12 -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: 18009 Received: (qmail 8844 invoked from network); 26 Sep 2013 23:36:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.223.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=4cxTfRUPvb+u4KBh61qPMjryjcUH1QRzqrDU168qFU0=; b=r23XATGWSZgjD67fQH38H6W5HdfznbbS/5Rts4pRJQXSF7wo3AZk9ihgfkdkbPrgsP DqT8aMkS06HrZ9BhI2s0qM4UbEsVbtjM2lXsxnvGEuvBpli2+C8yvEFJ9U0/m0ay95Uc E7mjKk0B2N6KdRTC5wL9YSg+zVdHNueyHb4ALT6jgTyxN9LtZav3goczzB8VnrXYPdOc 6YcYDiMUFmHIPx6UGPdBnCWUvb4ByCZtfTrwVNM8oQawcBw3dBq1Fk6nX8pLPHp8rHyl CtCL7QIm+o+kGBtTxwCp2j25P0q+KYpaNfi3gCTFCz+9AVgbh+fv7pET0CNeLQrmft/q QZdA== X-Received: by 10.42.42.132 with SMTP id t4mr168061ice.90.1380238561263; Thu, 26 Sep 2013 16:36:01 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: TJ Luoma Date: Thu, 26 Sep 2013 19:35:21 -0400 Message-ID: Subject: Re: Any way to have ".sh" be optional? To: Micah Elliott Cc: Zsh-Users List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, Sep 26, 2013 at 5:27 PM, Micah Elliott wrote= : > > On Thu, Sep 26, 2013 at 1:12 PM, TJ Luoma wrote: > > > > I tend to name all of my Zsh scripts to end with '.sh' so I can easily > > `fgrep -i Whatever *.sh` when I'm looking for something. > > Cool, I tend to use .zsh, but mostly so I know they're not system scripts= . Mine are all in ~/Dropbox/bin/ (which I've added to $PATH) so I know they aren't system scripts, and since my Dropbox only syncs between Macs I don't have to worry about cross platform script compatibility but I always have all of my scripts on all of my Macs :-) > > However, I would rather not have to type the ".sh" if not necessary. (Y= es, I > > am that lazy.) > > Leaving out the .=C2=ABtab=C2=BB saves a little bit of typing. But you mi= ght have > already fully tab-completed a couple chars in. Yup, I use 'tab' whenever possible to autocomplete. The problem is that I have recently converted some functions (which did not have ".sh" suffix) to scripts, mostly so I can call them from other scripts without putting them into .zsh(rc|env) but 'muscle memory' keeps me typing them the old way. > > is there a way to tell zsh "If I use the command 'foo' and there is no = 'foo' > > but there is 'foo.sh' then I want to use 'foo.sh'? > > You could tie into the command_not_found_hook (briefly mentioned in > zshmisc(1)). Something like this: > > command_not_found_handler() { > actual=3D$@[1].sh > print "Proxying for actual: $actual" > for p in $path; do > if [[ -x $p/$actual ]]; then > $actual $@[2,-1] > break > fi > done > } FYI this worked perfectly for me, and I love the touch of having it remind me that this is catching me when I type something incorrectly, which is more likely to help me remember to do it correctly in the future. I think. Theoretically. I definitely like what it does, regardless of its actual effect on my habits. > * I don't actually do this, but maybe I'll try; the func is not really > tested Worked as expected for me. > * zsh syntax highlighting > (https://github.com/zsh-users/zsh-syntax-highlighting) won't match fo= o I don't use that but now I'm going to head over and see what else is there = :-) > * running in cwd as ./foo isn't handled It is extremely unlikely that I would ever do `./foo` anyway. > * not sure if looping over path is best approach; would something with > hash work? It was certainly fast enough for me that I wouldn't spend time trying to optimize it. Even if it was slow it would be another way that maybe it would push me towards correcting my habit of mistyping. Thanks again. Tj