ianthehenry/sd

First usage issues

davidmankin opened this issue · 2 comments

Hi. I was trying to start using sd on my new macbook but ran into some challenges that I think are probably easy enough to fix.

I followed the installation instructions, so I have ~/bin/sd link to ~/sw/sd/sd. Then I type sd (after remembering to add bin to path):

/Users/mankin/bin/sd: line 12: $1: unbound variable

This is because I'm not passing anything to sd and it's ending up calling __sdcat with no arguments. I tried changing that with

diff --git a/sd b/sd
index f587be0..1075526 100755
--- a/sd
+++ b/sd
@@ -250,7 +250,12 @@ __sd() {
   elif [[ -x "$target" ]]; then
     SD="$(dirname "$target")" exec "$target" "$@"
   else
-    __sd_cat "$@"
+    if [[ $# -gt 0 ]]; then
+      __sd_cat "$@"
+    else
+      echo "sd requires at least one argument"
+      exit 0
+    fi
   fi
 }

But it's not entirely satisfying; would be better with some new-user help information.


Second issue is I (intentionally) didn't yet create ~/sd.

So I tried sd --help and I get

sed: /Users/mankin/sd: No such file or directory

which feels strange that it's sed complaining about a missing directory. Again feels like we could give some new user help.


Third try: sd help

cat: help: No such file or directory

Oof, yeah, that's pretty bad.

All of those errors stem from a missing ~/sd directory: there is no actual need to pass any arguments as your patch implies; sd works just fine without any arguments, as long as ~/sd exists. Although it isn't super friendly:

$ sd
sd commands

(no subcommands found)

$ sd --help
sd commands

(no subcommands found)

$ sd help
sd commands

(no subcommands found)

/Users/ian/sd/help not found

(The weird error from sd --help also comes from trying to generate help documentation from ~/sd/help when ~/sd doesn't exist.)

Anyway I pushed a patch that will give a more useful error message in this case:

$ sd
error: /Users/ian/sd not found

It looks like you don't have a script directory yet!

Get started by creating your first script:

    sd hello --new 'echo "Hello, sd!"'

And then run it like this:

    sd hello

Thanks!