<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[LoEE IoT blog]]></title><description><![CDATA[Turning ideas into products and problems into insights.]]></description><link>https://iot.loee.pl/</link><image><url>https://iot.loee.pl/favicon.png</url><title>LoEE IoT blog</title><link>https://iot.loee.pl/</link></image><generator>Ghost 4.0</generator><lastBuildDate>Sun, 12 Apr 2026 00:35:22 GMT</lastBuildDate><atom:link href="https://iot.loee.pl/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Juicing shell history]]></title><description><![CDATA[<p>Shell history is one of the best tools for augmenting our intellect when working with Unix apps. Remembering arcane incantations is no longer required if you can easily summon each and every one you used in the past 10 years. Here are a few helpful tricks I gathered over the</p>]]></description><link>https://iot.loee.pl/juicing-shell-history/</link><guid isPermaLink="false">5e57a75a694972126c12a001</guid><dc:creator><![CDATA[Jakub Piotr Cłapa]]></dc:creator><pubDate>Wed, 17 Mar 2021 19:19:41 GMT</pubDate><content:encoded><![CDATA[<p>Shell history is one of the best tools for augmenting our intellect when working with Unix apps. Remembering arcane incantations is no longer required if you can easily summon each and every one you used in the past 10 years. Here are a few helpful tricks I gathered over the years which helped me get the most of my shell history.</p><h2 id="avoid-the-export-builtin">Avoid the export builtin</h2><p>Your shell history will be more useful if you mostly avoid using the <code>export</code> builtin and instead set variables on the same line with the command that needs them. For example:</p><pre><code class="language-shell-session">CFLAGS=&quot;-arch i386&quot; CXXFLAGS=&quot;-arch i386&quot; LDFLAGS=&quot;-arch i386&quot; ./configure</code></pre><p>Such command line may get quite long but you can rerun this oneliner again next year just by searching for it in your history. In your own shell scripts this can be used as a replacement for keyword arguments when you do not remember the syntax for <code>getopt</code>.</p><p>This method only sets the variables for a single command so <code>export</code>ing a variable is still a good idea if you need to change something for the whole session.</p><h2 id="up-arrow-prefix-history-search">Up-arrow prefix history search</h2><p>Trying to remember this long docker command you ran last week? What if you only needed to write <code>docker</code> and press the up arrow?</p><!--kg-card-begin: html--><script id="asciicast-GHadgV4pmi4YsiwqGAeQyjGRU" src="https://asciinema.org/a/GHadgV4pmi4YsiwqGAeQyjGRU.js" async></script><!--kg-card-end: html--><p>Normally pressing the up arrow will bring up previous commands one-by-one but if you are a frequent shell user chances are that the command you are looking for is probably buried quite deep. <code>Ctrl-R</code> does bring up an incremental search widget but navigating it requires peculiar key bindings which I&apos;ll never remember. With the two lines shown below any tool using readline will do a prefix search with whatever is currently typed to the left of your cursor:</p><figure class="kg-card kg-code-card"><pre><code>&quot;\e[A&quot;: history-search-backward
&quot;\e[B&quot;: history-search-forward</code></pre><figcaption>Add these two lines to the <code>~/.inputrc</code> file (these work in any program using readline, not only in bash and zsh).</figcaption></figure><h2 id="better-ctrl-r">Better <code>Ctrl-R</code></h2><p>I did mention that <code>Ctrl-R</code> is frustrating, didn&apos;t I? While frustrating and antique it is quite useful when you remember something about the arguments or files involved but not the command name (so the up-arrow prefix search is not useful).</p><p>Certainly the quickest tool to find something in your shell history is <code>grep</code>.</p><figure class="kg-card kg-code-card"><pre><code class="language-shell-session">[jpc@jpc a-dox] grep ./configure ~/.zhistory
: 1615894760:0;CPPFLAGS=&quot;-I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/ncurses/include&quot; LDFLAGS=&quot;-L/opt/homebrew/opt/gettext/lib -L/opt/homebrew/opt/ncurses/lib&quot; LIBS=-lintl LIBTOOL=/opt/homebrew/bin/glibtool ./configure --enable-local
</code></pre><figcaption>Grepping through 10 years of shell history (every line begins with a timestamp, the actual command begins after the <code>;</code>). If you use bash, replace <code>.zhistory</code> with <code>.bash_history</code>.</figcaption></figure><p>It&apos;s an amazingly good way to find what you are looking for mostly because you can see all related items at once instead of checking them one at a time with Ctrl-R. You can also quite easily copy and paste a series of commands into an editor to clean them up and turn them into a shell script.</p><p>Btw. using your favourite editor on the history file is also very useful.</p><h2 id="fancier-ctrl-r">Fancier Ctrl-R</h2><p><code>grep</code> is great but a bit boring? We can spice it up using <a href="https://github.com/junegunn/fzf">fzf</a>. It&apos;s a tool written in Go that allows you to select stuff in a text-mode UI. The install script will setup a nice Ctrl-R keybinding that let&apos;s you interactively filter through your shell history to find the command you need.</p><p>Let&apos;s say I used crosstool-ng to build a toolchain for ESP8266. I know I have to run the command <code>./ct-ng</code> but sometimes I set some ENV variables so it the command name does not come first on the command line:</p><!--kg-card-begin: html--><script id="asciicast-ViBCYxtUOwnhx1S4bS4QdDeG2" src="https://asciinema.org/a/ViBCYxtUOwnhx1S4bS4QdDeG2.js" async></script><!--kg-card-end: html--><p>One interesting tidbit is that hitting Enter does not replace whatever you may have typed but will paste the selected history line in-place instead. This is great if you wish to join several commands with <code>&amp;&amp;</code> to make a one-liner which you can repeat with a simple up arrow.</p>]]></content:encoded></item></channel></rss>