<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Unformed Delta - cli</title>
    <description>A place to collect the things I learn, figure out, or find interesting.
</description>
    <link>https://unformeddelta.wiki/</link>
    <atom:link href="https://unformeddelta.wiki/feed/cli.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sat, 09 May 2026 14:44:19 +0000</pubDate>
    <lastBuildDate>Sat, 09 May 2026 14:44:19 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
    <item>
      <title>Defining custom units for the units CLI</title>
      <description>&lt;p&gt;I recently started using a Glowforge Aura to laser cut stuff. So far I made a copy of the game Hex, designed an organizer for Kingdom Builder’s tiny hexagons that are a pain to sort, and plan to also try my hand at creating custom Jig-Saw Puzzles.&lt;/p&gt;

&lt;p&gt;While designing the Kingdom Builder organizer, I needed to measure game pieces using callipers and then cut out pieces of EVA foam with the correct size. Through a little bit of trial and error I determined that a 1151px square SVG exported from Figma (vector editing) was the largest size that didn’t get resized when importing it into the Glowforge software and corresponded to the complete size of the Glowforge Aura’s available cutting bed which is a 1ft / 304.8mm square.&lt;/p&gt;

&lt;p&gt;Performing these conversions using a calculator was annoying.&lt;/p&gt;

&lt;p&gt;I just discovered the &lt;a href=&quot;/80ez771I2kAJ/performing-unit-conversions-on-the-cli&quot;&gt;units CLI&lt;/a&gt;, and it makes it pretty easy to define custom units. I defined a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gf&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glowforge&lt;/code&gt; unit which represents 1 pixel in Figma’s coordinate space:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# Figma pixels to millimeters conversion for Glowforge Aura
glowforge			304.8|1151 millimeter
gf		glowforge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I couldn’t figure out how to get the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;units&lt;/code&gt; to combine my custom units with its existing definitions, but it was easy to define an alias that combined the system library with my custom definitions:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;units() {
  command units -f &amp;lt;(cat /usr/share/misc/units.lib &quot;$DOTFILES/custom-units.lib&quot;) &quot;$@&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now I can do &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;units &apos;25 mm&apos; gf&lt;/code&gt; to see that I should make my design 94.406168px in Figma.&lt;/p&gt;
</description>
      <pubDate>Sun, 01 Feb 2026 06:37:00 +0000</pubDate>
      <link>https://unformeddelta.wiki/EaF5QphkhxlD/defining-custom-units-for-the-units-cli</link>
      <guid isPermaLink="true">https://unformeddelta.wiki/EaF5QphkhxlD/defining-custom-units-for-the-units-cli</guid>
      
      <category>cli</category>
      
      <category>lasercutting</category>
      
    </item>
    
    <item>
      <title>Performing unit conversions on the CLI</title>
      <description>&lt;p&gt;I recently discovered&lt;sup id=&quot;fnref:how-I-discovered-it&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:how-I-discovered-it&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;units&lt;/code&gt; CLI tool which installed by default on macOS/Linux and comes with a ton of builtin conversions. For example you can do:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;❯ units &apos;12 tablespoons&apos; cups
	* 0.75
	/ 1.3333333
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This tells you that 12 tablespoons is 0.75 cups, or that a cup is approximately 1.3333333 times 12 tablespoons. I don’t really have any idea why it also shows the latter, but it’s easy enough to ignore.&lt;/p&gt;

&lt;p&gt;It also has an interactive mode that reduces the need for quoting shell arguments, e.g.:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;❯ units
753 units, 62 prefixes
You have: 190 degC
You want: degF
	374
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It also handles compound units seamlessly:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;❯ units &apos;10 m/s&apos; mph
	* 22.369363
	/ 0.044704
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;One gotcha you have to watch out for is that numbers need to be separated from units by spaces, otherwise you get a conformability error and a gibberish result:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;❯ units 10mm cm
conformability error
	10
	0.01 m
❯ units &apos;10 mm&apos; cm
	* 1
	/ 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;One of the most amazing things is the file containing the builtin unit definitions. On macOS 26 it is located at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/share/misc/units.lib&lt;/code&gt;. It starts out simple defining primitive units and prefixes:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# primitive units

m			!a!
kg			!b!
sec			!c!
[...]

# prefixes

[...]
kilo-			1e3
hecto-			1e2
deka-			1e1
deca-			deka
deci-			1e-1
centi-			1e-2
milli-			1e-3
micro-			1e-6
[...]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But it also contains a lot of (at least to me) extremely obscure units. For example, did you know that it takes 16 US feet make 15 French feet?&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;frenchfoot		16|15 ft
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You also can &lt;a href=&quot;/EaF5QphkhxlD/defining-custom-units-for-the-units-cli&quot;&gt;define your own custom conversions&lt;/a&gt; for your own unique use cases.&lt;/p&gt;

&lt;p&gt;I frequently find it convenient to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bc&lt;/code&gt; as a calculator on the command line in my dropdown terminal instead of using a browser/search engine, so I imagine I’ll use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;units&lt;/code&gt; in the future when remembering or typing the conversion into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bc&lt;/code&gt; is too inconvenient.&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:how-I-discovered-it&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;I read the short story &lt;a href=&quot;https://web.mit.edu/jemorris/humor/500-miles&quot;&gt;500 Miles&lt;/a&gt; and was intrigued / didn’t get the punchline because I’d never heard of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;units&lt;/code&gt;. To my surprise, it just existed. &lt;a href=&quot;#fnref:how-I-discovered-it&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
      <pubDate>Sun, 01 Feb 2026 06:37:00 +0000</pubDate>
      <link>https://unformeddelta.wiki/80ez771I2kAJ/performing-unit-conversions-on-the-cli</link>
      <guid isPermaLink="true">https://unformeddelta.wiki/80ez771I2kAJ/performing-unit-conversions-on-the-cli</guid>
      
      <category>cli</category>
      
      <category>recommended</category>
      
    </item>
    
  </channel>
</rss>
