Fork me on GitHub
#planck
<
2016-08-12
>
kauko11:08:49

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.

kauko11:08:30

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/" ..}

mfikes11:08:30

@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]))

kauko11:08:03

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

kauko11:08:08

is it not meant to do that?

manutter5111:08:26

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

manutter5111:08:59

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

kauko11:08:09

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

kauko11:08:28

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

kauko11:08:30

from planck

kauko11:08:12

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

mfikes11:08:28

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

kauko11:08:47

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

mfikes11:08:14

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

manutter5111:08:45

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

kauko11:08:46

It's a fish command

mfikes11:08:55

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

kauko11:08:17

manutter51, I'll try that 🙂

kauko12:08:35

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)

manutter5112:08:15

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

mfikes12:08:33

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

mfikes12:08:54

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

manutter5112:08:08

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

manutter5112:08:45

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

mfikes12:08:18

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.

mfikes12:08:28

@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 “"}

manutter5112:08:47

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

kauko12:08:50

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 😄

kauko12:08:11

@mfikes: awesome, thanks!

kauko12:08:32

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

kauko12:08:40

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

mfikes12:08:04

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

kauko12:08:10

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?

mfikes12:08:13

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

kauko12:08:21

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

kauko12:08:36

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

kauko12:08:01

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

kauko12:08:23

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

kauko12:08:26

But for only 3 folders

kauko12:08:22

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

mfikes12:08:27

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.