<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Shell on galvanist</title>
    <link>/tags/shell/</link>
    <description>Recent content in Shell on galvanist</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Wed, 20 Nov 2013 01:17:55 +0000</lastBuildDate>
    <atom:link href="/tags/shell/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Manpages in the GUI on OS X</title>
      <link>/posts/2013-11-20-manpages-in-the-gui-on-os-x/</link>
      <pubDate>Wed, 20 Nov 2013 01:17:55 +0000</pubDate>
      <guid>/posts/2013-11-20-manpages-in-the-gui-on-os-x/</guid>
      <description>&lt;p&gt;Here&amp;rsquo;s a shell function to add to your profile that makes it easy to view man pages in OS X&amp;rsquo;s Preview.app:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;pman&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{&lt;/span&gt; man -t &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$*&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; open -f -a &lt;span class=&#34;s2&#34;&gt;&amp;#34;/Applications/Preview.app&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    <item>
      <title>OS X Quick Look Preview on the Command-line</title>
      <link>/posts/2013-11-18-os-x-quick-look-preview-on-the-command-line/</link>
      <pubDate>Mon, 18 Nov 2013 20:56:41 +0000</pubDate>
      <guid>/posts/2013-11-18-os-x-quick-look-preview-on-the-command-line/</guid>
      <description>&lt;p&gt;The &lt;code&gt;qlmanage&lt;/code&gt; command has a &lt;code&gt;-p&lt;/code&gt; argument which lets you create &lt;a href=&#34;http://en.wikipedia.org/wiki/Quick_Look&#34;&gt;Quick Look&lt;/a&gt; previews on the command line. So something like this can be nice to have in your shell profile: &lt;code&gt;alias ql=&#39;qlmanage -p&#39;&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I decided I needed something a little more featurey than an alias (because &lt;code&gt;qlmanage -p README&lt;/code&gt; is useless). So, I made a &lt;a href=&#34;https://github.com/glvnst/shelltools/blob/master/ql.py&#34;&gt;quick python implementation of ql&lt;/a&gt; which has special treatment for &lt;code&gt;README&lt;/code&gt;, &lt;code&gt;LICENSE&lt;/code&gt;, &lt;code&gt;Makefile&lt;/code&gt; and probably eventually other extension-less file names.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Revisiting Shell Concurrency (this time in ZSH)</title>
      <link>/posts/2013-11-15-revisiting-shell-concurrency-this-time-in-zsh/</link>
      <pubDate>Fri, 15 Nov 2013 23:08:00 +0000</pubDate>
      <guid>/posts/2013-11-15-revisiting-shell-concurrency-this-time-in-zsh/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve been thinking about &lt;a href=&#34;http://galvanist.com/post/51134915590/managed-concurrency-in-the-bash-shell&#34;&gt;concurrency in the command shell&lt;/a&gt; again. This was prompted by my ongoing transition from Bash to ZSH. I&amp;rsquo;ve decided to re-implement my &lt;code&gt;conc&lt;/code&gt; and &lt;code&gt;xconc&lt;/code&gt; functions in a slightly different way.&lt;/p&gt;&#xA;&lt;h2 id=&#34;intro&#34;&gt;Intro&lt;/h2&gt;&#xA;&lt;p&gt;Lets say you have 50 data files to compress. Here&amp;rsquo;s one way:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;% xz *.dat&#xA;&amp;lt;&amp;lt; completed in 2 minutes, 4 seconds &amp;gt;&amp;gt;          &#xA;%&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&amp;rsquo;s not bad, but it doesn&amp;rsquo;t really take advantage of all those fancy cores we have in our computers these days. Let&amp;rsquo;s run multiple &lt;code&gt;xz&lt;/code&gt; jobs as-parallel-as-possible, so that each file gets its own &lt;code&gt;xz&lt;/code&gt; process.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Sort du intelligently </title>
      <link>/posts/2013-10-22-sort-du-intelligently/</link>
      <pubDate>Tue, 22 Oct 2013 17:14:00 +0000</pubDate>
      <guid>/posts/2013-10-22-sort-du-intelligently/</guid>
      <description>&lt;p&gt;The &lt;code&gt;du&lt;/code&gt; command is a nice tool for telling you the disk usage of your files:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-txt&#34; data-lang=&#34;txt&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ du *&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;[...]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;1928&#x9;system.log&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;136&#x9;system.log.0.bz2&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;112&#x9;system.log.1.bz2&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;0&#x9;uucp&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;552&#x9;vnetlib&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;[...]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I find that adding the &lt;code&gt;-h&lt;/code&gt; flag (which produces more human-readable output) is often very helpful for me:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-txt&#34; data-lang=&#34;txt&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;$ du -h *&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;[...]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;964K&#x9;system.log&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; 68K&#x9;system.log.0.bz2&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; 56K&#x9;system.log.1.bz2&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  0B&#x9;uucp&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;276K&#x9;vnetlib&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;[...]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now if I could just sort that&amp;hellip;&lt;/p&gt;</description>
    </item>
    <item>
      <title>collect - a shell function</title>
      <link>/posts/2013-05-24-collect---a-shell-function/</link>
      <pubDate>Fri, 24 May 2013 22:41:00 +0000</pubDate>
      <guid>/posts/2013-05-24-collect---a-shell-function/</guid>
      <description>&lt;p&gt;&lt;img src=&#34;oldsite_inline_mnbokvaXuG1qz4rgp.gif&#34; alt=&#34;Animation of &amp;ldquo;New Folder with Selection&amp;rdquo; Finder Function&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;In OS X&amp;rsquo;s Finder, if you select some things then right-click you have an option called &amp;ldquo;New Folder with Selection&amp;rdquo;. ilikeitverymuch. So a while back, I though it would be alsonice to have something analogous in the command shell. I&amp;rsquo;ve been using just such a command for about six months now and let me assure you that it is &lt;em&gt;very&lt;/em&gt; alsonice.&lt;/p&gt;&#xA;&lt;p&gt;What does it do, under the hood?&lt;/p&gt;</description>
    </item>
    <item>
      <title>Managed concurrency in the bash shell</title>
      <link>/posts/2013-05-23-managed-concurrency-in-the-bash-shell/</link>
      <pubDate>Thu, 23 May 2013 07:14:00 +0000</pubDate>
      <guid>/posts/2013-05-23-managed-concurrency-in-the-bash-shell/</guid>
      <description>&lt;p&gt;Concurrency is all the rage these days. I started to wonder about using it in my command shell (which is regrettably still bash) because so much of the infrastructure for job control is already in place. I&amp;rsquo;ve been using &lt;code&gt;xargs -P&lt;/code&gt; for a while, but I wondered about doing it all in the shell.&lt;/p&gt;&#xA;&lt;h2 id=&#34;conc&#34;&gt;&amp;ldquo;conc&amp;rdquo;&lt;/h2&gt;&#xA;&lt;p&gt;I came up with a super-simple function to do some experiments:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;export&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;CONC_MAX&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;conc&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#x9;&lt;span class=&#34;nb&#34;&gt;local&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;procs&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=(&lt;/span&gt;&lt;span class=&#34;sb&#34;&gt;`&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;jobs&lt;/span&gt; -p&lt;span class=&#34;sb&#34;&gt;`&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#x9;&lt;span class=&#34;nb&#34;&gt;local&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;proc_count&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;${#&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;procs&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[*]&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#x9;&lt;span class=&#34;c1&#34;&gt;# Block until there is an open slot&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#x9;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;((&lt;/span&gt;proc_count &amp;gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; CONC_MAX&lt;span class=&#34;o&#34;&gt;))&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#x9;&#x9;&lt;span class=&#34;nb&#34;&gt;wait&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#x9;&lt;span class=&#34;k&#34;&gt;fi&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#x9;&lt;span class=&#34;c1&#34;&gt;# Start our task&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#x9;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;eval&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$@&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;&amp;amp;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;export&lt;/span&gt; -f conc&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To use it, just throw the word &amp;lsquo;conc&amp;rsquo; in front of your commands. It will only use up to CONC_MAX processes. I matched that to the number of cores I have. It is especially useful in loops. For example, while this does some things:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
