zsh-users
 help / color / mirror / code / Atom feed
From: TJ Luoma <luomat@gmail.com>
To: Micah Elliott <mde@micahelliott.com>
Cc: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: Any way to have ".sh" be optional?
Date: Thu, 26 Sep 2013 19:35:21 -0400	[thread overview]
Message-ID: <CADjGqHs6kOFU-E2MCQhb9yOhK4XDpv2Gh0KaEhsf5TBThrPd2w@mail.gmail.com> (raw)
In-Reply-To: <CAELbujqMfX7Sgrr=JtJ8HZey6N4TwfyvS44J1XPvJJ3sOFs4=w@mail.gmail.com>

On Thu, Sep 26, 2013 at 5:27 PM, Micah Elliott <mde@micahelliott.com> wrote:

>

> On Thu, Sep 26, 2013 at 1:12 PM, TJ Luoma <luomat@gmail.com> 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. (Yes, I

> > am that lazy.)

>

> Leaving out the .«tab» saves a little bit of typing. But you might 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=$@[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 foo


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


  reply	other threads:[~2013-09-26 23:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-26 20:12 TJ Luoma
2013-09-26 20:39 ` Jérémie Roquet
2013-09-26 21:27 ` Micah Elliott
2013-09-26 23:35   ` TJ Luoma [this message]
2013-09-26 21:40 ` Bart Schaefer
2013-09-26 23:18 ` TJ Luoma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADjGqHs6kOFU-E2MCQhb9yOhK4XDpv2Gh0KaEhsf5TBThrPd2w@mail.gmail.com \
    --to=luomat@gmail.com \
    --cc=mde@micahelliott.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).