Fork me on GitHub
#cursive
<
2022-12-19
>
helios13:12:37

@cfleming did you ever get around to implement the support for matcher combinators? https://github.com/nubank/matcher-combinators/issues/31#issuecomment-1165997443

cfleming20:12:58

I actually have this half done in a branch, and it鈥檚 still slated for the next release.

馃檹 3
鉂わ笍 3
馃憦 3
markaddleman16:12:28

My workflow includes frequently printing a SQL string to the REPL and then copying the string to the clipboard so I can paste it into a db tool. I鈥檇 like to automate copying the string to the clipboard. Is there some intellij scripting magic for this?

markaddleman17:12:15

Your google fu is more powerful than mine 馃檪

imre17:12:23

I think it would probably be easier to go straight to the clipboard from clojure than get intellij involved

markaddleman17:12:55

I had assumed that intellij had to be involved but your solution is better

imre17:12:27

putting to the clipboard is just another side effect, like printing to out is

onetom10:01:47

https://github.com/AvisoNovate/pretty has io.aviso.clipboard/{copy,paste}, which uses the same approach as the mentioned gist. in that past at least, that approach had the side-effect of opening a window-less app on macOS and it also took quite some time to initialize the graphical subsystem in java, before u could talk to the clipboard. so u might want to just shell out instead and use pbcopy / pbpaste on macOS, for example. it's not very cross platform of course...

(defn pbpaste [] (-> "pbpaste" direnv/stdout-of))

onetom10:01:10

where direnv/stdout-of is defined as

(ns ginoco.direnv
  (:require
    [clojure.java.shell :as shell]
    [clojure.string :as str]))

(defn env+
  "Merge extra env vars into the specified or current process environment."
  ([extra-env]
   (env+ (System/getenv) extra-env))
  ([current-env extra-env]
   (reduce into {} [current-env extra-env])))

(def muted-direnv {"DIRENV_LOG_FORMAT" ""})

(comment
  (env+ muted-direnv))

(defn stdout-of
  "Returns the standard output of the specified command line, also trimming the
   last newline from it.

   If the standard error is not empty, then throws an exception with it as
   the exception message."
  [& args]
  (let [{:keys [out err exit] :as res} (apply shell/sh args)]
    ;(prn res)
    (if (zero? exit)
      (if (string? out)
        (str/trim-newline out)
        out)
      (-> (str (vec args) " exited with status: " exit "\n" out err)
          (ex-info res)
          throw))))

(comment
  (stdout-of "echo" "blah")
  (stdout-of "/usr/bin/false")
  )

(defn exec
  "Eg:
     (direnv/exec \"firefox\" \"--profile\" \"test\")

   which translates to:

     DIRENV_LOG_FORMAT='' direnv exec . firefox --profile test"
  [& args]
  (shell/with-sh-env
    (env+ muted-direnv)
    (apply stdout-of "direnv" "exec" "." args)))

(defn which [prg] (exec "which" prg))

(comment
  (exec "bash" "-c" "type $SHELL")
  (which "clojure")
  )