rpav / ScriptL

Shell scripting made Lisp-like! Or, live-coding remote function calls for the shell.
73 stars 11 forks source link

[Questions] Script and run directories #6

Closed dieggsy closed 7 years ago

dieggsy commented 7 years ago

I was wondering:

rpav commented 7 years ago

Actually they should not; when scripts get called in, *default-pathname-defaults* should be bound to the caller's cwd. This should be enough for anything inside the lisp, using merge-pathnames, but you may want to pass it on to things like run-program, where it's unfortunate *default-pathname-defaults* isn't the default.

dieggsy commented 7 years ago

@rpav Ah, I see. when using

(defun my-ls ()
  (dolist (file (directory "*.*"))
    (write-line (namestring file))))

instead, it works as expected. Thanks! So there's no way around this with run-program?

Also, what about making scripts in a different directory than *default-pathname-defaults* ?

rpav commented 7 years ago

If you mean SBCL's run-program, just pass it :directory *default-pathname-defaults*. Others are likely similar.

For make-script, try locally binding it, e.g.,

(let ((*default-pathname-defaults* #P"/path/to/script"))
  (make-script ...)

I'm actually not 100% sure this works, and if it doesn't it's a legit bug. There should be (and it would be trivial to write) something like with-path so you could just do:

(with-path (#P"...")
  ...)

This would save typing out long ugly variable names if you do this a lot.

dieggsy commented 7 years ago

Great, all of this seems to work. Thanks!

EDIT: (Briefly did something sorta dumb, but it's sorted out now).

rpav commented 7 years ago

Try with bef41db, apparently it wasn't doing merge-pathnames on the actual target usage.