planck

Planck ClojureScript REPL
kauko 2016-08-12T11:19:49.000213Z

Hey, I'm trying to run shell commands from planck, but can't get it to work. I'm using a fish shell, if that matters.

kauko 2016-08-12T11:23:30.000214Z

planck
(require '[planck.shell :as shell])
(shell/sh "pwd") => {.. :out "currentfolder/" ..}
(shell/sh "ls") => {:out "some/ folders/"}
(shell/sh "cd some") => launch path not accessible
(shell/sh "cd" "some") => {:exit 0 :out "" :err ""}
(shell/sh "pwd") => {.. :out "currentfolder/" ..}

mfikes 2016-08-12T11:33:30.000218Z

@kauko: Glad to help: Planck is designed to behave like clojure.java.shell, which pretty much matches what you show above. If you’d like to execute a command in some other directory, you can

(shell/with-sh-dir “some"
  (shell/sh "pwd”))
(You’ll need to (require-macros '[planck.shell :as shell]))

kauko 2016-08-12T11:41:03.000220Z

Oh, what I meant is, the (shell/sh "cd" "some") does not seem to actually change the directory in which I am

kauko 2016-08-12T11:41:08.000221Z

is it not meant to do that?

2016-08-12T11:44:26.000222Z

Try running (shell/sh “echo” “$$”) a couple times and see if it gives you the same process ID

2016-08-12T11:45:59.000223Z

Just wondering if it’s doing the cd in a sub-process instead of changing the directory in the process you’re running from

kauko 2016-08-12T11:46:11.000224Z

oh

kauko 2016-08-12T11:46:14.000225Z

hmm

kauko 2016-08-12T11:53:09.000226Z

Alright, my previous question was mostly me trying to figure planck out

kauko 2016-08-12T11:53:28.000227Z

but what I'm actually trying to do, is run a fish script in the shell

kauko 2016-08-12T11:53:30.000228Z

from planck

kauko 2016-08-12T11:54:12.000229Z

(shell/with-sh-dir my-folder (shell/sh "for" "i" "in ".svg*;" "pwd")) gives "launch path not accessible".

mfikes 2016-08-12T11:54:28.000230Z

Yes, I believe (shell/sh "cd" "some”) changes directory, but it is like a “tree falling in a forest."

kauko 2016-08-12T11:54:47.000231Z

I don't know if this is related to the java.shell thing you mentioned, I don't really know what that means tbh 😄

mfikes 2016-08-12T11:55:14.000232Z

For your for example: for is not a program, right?

2016-08-12T11:55:45.000233Z

I think you need to put your fish shell commands into an executable script and then use shell/sh to execute the script

kauko 2016-08-12T11:55:46.000234Z

It's a fish command

mfikes 2016-08-12T11:55:55.000235Z

(shell/sh "cd" "some”) changes directory, but there is nothing executed in that directory afterwards in order to make use of its side effect

kauko 2016-08-12T11:56:17.000236Z

manutter51, I'll try that 🙂

kauko 2016-08-12T12:00:35.000237Z

Ugh, it's not working. There's so many places where this can go wrong, and I'm getting so little feedback (it's not planck's fault entirely, I don't have much experience with scripting fish)

2016-08-12T12:01:15.000238Z

Maybe you could leave fish out of the loop entirely and just write the whole script in planck/cljs?

mfikes 2016-08-12T12:01:33.000239Z

Do you have a working Fish script? (Meaning can you run it outside of Planck?)

mfikes 2016-08-12T12:01:54.000240Z

@manutter51: Actually, that’s a compelling idea 🙂

2016-08-12T12:02:08.000241Z

I’ve done it some, it’s really fun

2016-08-12T12:02:45.000243Z

I’ve been looking for a good command-line clj tool ever since jark faded into obscurity, planck is awesome

mfikes 2016-08-12T12:03:18.000244Z

For example, you can use planck.core/file-seq and then use Clojure sequence abstractions (even with doseq for example), to easily cobble together scripts.

mfikes 2016-08-12T12:06:28.000245Z

@kauko: I’ve confirmed Planck can run executable scripts written using Fish. For example myscript containing

#!/usr/local/bin/fish
pwd
works
cljs.user=> (shell/sh "myscript")
{:exit 0, :out "/Users/mfikes/Desktop\n", :err “"}

2016-08-12T12:06:47.000246Z

I wrote a script that scans through JBoss log files and prints out the stack traces of exceptions, based on the observation that the stack traces are all indented

kauko 2016-08-12T12:06:50.000247Z

Yeah, that's what I probably should do (do everything with planck), but this is a script I'll have run very rarely, and honestly I've spent way too much time with this already 😄

kauko 2016-08-12T12:07:11.000248Z

@mfikes: awesome, thanks!

kauko 2016-08-12T12:07:32.000250Z

I realised that when I use the macro to run a command in another folder, the script doesn't exist in THAT folder

kauko 2016-08-12T12:07:40.000251Z

I guess I'll have to get an absolute path to the script

mfikes 2016-08-12T12:12:04.000253Z

@kauko: Right. Absolute path works. (And FWIW, that behavior is consistent with clojure.java.shell.)

kauko 2016-08-12T12:14:10.000254Z

Hmm, I think I got to work with the absolute path. Any way I can print the output though? I guess it's not printing because of the with-dir macro?

mfikes 2016-08-12T12:15:13.000255Z

The output of your Fish script should be included in :out and :err of the return value of planck.shell/sh.

kauko 2016-08-12T12:19:21.000256Z

Hmm, but if the script I'm running has a for loop with an echo

kauko 2016-08-12T12:19:36.000257Z

I won't get the :out before the script finishes, right?

mfikes 2016-08-12T12:19:50.000258Z

Right.

kauko 2016-08-12T12:20:01.000259Z

Oh, well, that doesn't really help me that much 🙂

kauko 2016-08-12T12:20:23.000260Z

This is a script that generates .png files from .svg files, so it runs for a pretty long time per folder.

kauko 2016-08-12T12:20:26.000261Z

But for only 3 folders

kauko 2016-08-12T12:22:22.000262Z

Thanks a bunch for planck btw. We've used it for a couple of things now 🙂 One of my team mates made a planck script for bitbar, that shows our open pull requests from github

1😃
mfikes 2016-08-12T12:22:27.000263Z

Yeah, if you want to execute a command on all of the *.svg files in a folder, and indicate output as things proceed, you can use Planck to do that. (I actually did something like that recently using Image Magick.