Skip to content

Latest commit

 

History

History
249 lines (193 loc) · 7.37 KB

scripts.md

File metadata and controls

249 lines (193 loc) · 7.37 KB

Scripts

The following scripts are under bin/:

bb-github-pr-for-commit

Prints github url of PR associated with a commit. It assumes a current directory's repository but any repository can be specified. See https://github.com/mislav/hub-api-utils/blob/master/bin/hub-pr-with-commit for an alternative implementation.

Setup

Usage

# Prints url and opens url for osx
$ ./bb-github-pr-for-commit -r atom/atom 0f521f1e8afbcaf73479ea93dd4c87d9187903cb
"https://github.com/atom/atom/pull/20350"

# Open url of current github repository
$ ./bb-github-pr-for-commit SHA

bb-github-repo

For the current github repo, open different repo urls e.g. commit or branch. Inspired by this ruby version.

To open a commit, bb-github-repo -c SHA.

bb-table

Usage

Prints an ascii table given an EDN collection on stdin or as a file:

$ echo '[{:a 4 :b 2} {:a 2 :c 3}]' | bb-table

| :a | :b | :c |
|----+----+----|
|  4 |  2 |    |
|  2 |    |  3 |

$ bb-table -f something.edn
...

bb-project-clj

Prints a project.clj defproject form as a map. Useful for manipulating this data on the commandline

# Pretty prints a project's dependencies
$ bb-project-clj -d 1 | bb -I '(-> *input* first :dependencies clojure.pprint/pprint)'

bb-replace

Replaces a substring in a file using a regex to match it. Much less powerful than sed but more user friendly as it supports configuring and naming regexs. bb-replace reads configs found in ~/.bb-replace.edn and ./bb-replace.edn. See script for documentation on config format.

# Use the default name replacements provided
$ cp .bb-replace.edn ~/.bb-replace.edn

# Navigate to a lein project and update project's version
$ bb-replace lein-version 1.2.1

# Navigate to a nodejs project and update project's version
$ bb-replace json-version 2.1.1

# A one-off regex can be used. This updates a map entry to false
$ bb-replace -f project.clj -F '$1 %s' "(:pseudo-names)\s+\w+" false

bb-vis

Generates vega-lite visualizations given vega-lite data as a file or on stdin. Data file can be json or edn.

Setup

Install vega-lite cmds with yarn global add vega-lite --peer && yarn global add canvas. This was last confirmed to work with vega-lite 5.1.0 and canvas 2.8.0.

Usage

Assume you have the following bar.edn:

{:data
  {:values
   [{:a "A", :b 28}
    {:a "B", :b 55}
    {:a "C", :b 43}
    {:a "D", :b 91}
    {:a "E", :b 81}
    {:a "F", :b 53}
    {:a "G", :b 19}
    {:a "H", :b 87}
    {:a "I", :b 52}]},
  :mark "bar",
  :encoding
  {:x {:field "a", :type "ordinal", :axis {:labelAngle 0}},
   :y {:field "b", :type "quantitative"}}}

To generate this image and open it: bb-vis bar.edn -o.

To generate this image as a pdf and open it: bb-vis bar.edn -F pdf -o

Generated image:

this

Any of the official examples can be generated by simply copying and pasting the data to stdin. For example, let's try the 2D histogram heatmap:

cat <<EOF | bb-vis -o
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {"url": "data/movies.json"},
  "transform": [{
    "filter": {"and": [
      {"field": "IMDB_Rating", "valid": true},
      {"field": "Rotten_Tomatoes_Rating", "valid": true}
    ]}
  }],
  "mark": "rect",
  "width": 300,
  "height": 200,
  "encoding": {
    "x": {
      "bin": {"maxbins":60},
      "field": "IMDB_Rating",
      "type": "quantitative"
    },
    "y": {
      "bin": {"maxbins": 40},
      "field": "Rotten_Tomatoes_Rating",
      "type": "quantitative"
    },
    "color": {
      "aggregate": "count",
      "type": "quantitative"
    }
  },
  "config": {
    "view": {
      "stroke": "transparent"
    }
  }
}
EOF

Generated image:

this

bb-try

Try a Clojure library easily with bb. Inspired by https://github.com/avescodes/lein-try.

# Adds latest version of this library to classpath and starts repl
$ bb-try camel-snake-kebab

# Any additional arguments are passed on to bb
$ bb-try camel-snake-kebab "(require '[camel-snake-kebab.core :as csk]) (csk/->SCREAMING_SNAKE_CASE :babashka-classpath)"
:BABASHKA_CLASSPATH

Currently it only fetches the latest version of a library but I'm thinking of making a version optional.

bb-ns-dep-tree

Print the ns dependency tree for a given ns or file. For example, if we want to print the dependencies of datascript.datafy:

# On a local checkout of datascript
$ bb-ns-dep-tree src/datascript/datafy.cljc
datascript.datafy
├── clojure.core.protocols
├── datascript.pull-api
│   ├── datascript.db ...
│   └── datascript.pull-parser
│       └── datascript.db ...
├── datascript.db
│   ├── clojure.walk
│   ├── clojure.data
│   ├── me.tonsky.persistent-sorted-set
│   └── me.tonsky.persistent-sorted-set.arrays
└── datascript.impl.entity
    ├── clojure.core
    └── datascript.db ...

# We can also print the cljs dependencies of the same ns
$ bb-ns-dep-tree -l cljs datascript.datafy
datascript.datafy
├── clojure.core.protocols
├── datascript.pull-api
│   ├── datascript.db ...
│   └── datascript.pull-parser
│       └── datascript.db ...
├── datascript.db
│   ├── goog.array
│   ├── clojure.walk
│   ├── clojure.data
│   ├── me.tonsky.persistent-sorted-set
│   ├── me.tonsky.persistent-sorted-set.arrays
│   └── datascript.db ...
└── datascript.impl.entity
    ├── cljs.core
    └── datascript.db ...

bb-update-lein-dependency

Updates lein dependency of specified directories and optionally commits and pushes the change. For example, if I'm in the dependency's directory and I want to update two dependent projects to use its latest SHA, commit and git push:

bb-update-lein-dependency -c -d ../proj1 -d ../proj2 my-dep $(git rev-parse HEAD).

bb-logseq-convert

Given a url, returns auto populated properties as a logseq block. The properties are derived from the url's rdf data and what is converted to the logseq block is highly configurable.

bb-logseq-move-to-page

Given a logseq text block with a name property, moves that block to a logseq page.

Logseq scripts

Scripts starting with bb-logseq- are a group of scripts for use with logseq. My config of these scripts are in this directory.