<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>notes from /dev/null - unix</title><link href="http://yummymelon.com/devnull/" rel="alternate"/><link href="http://yummymelon.com/devnull/feeds/tags/unix.atom.xml" rel="self"/><id>http://yummymelon.com/devnull/</id><updated>2025-01-17T05:30:00-08:00</updated><entry><title>Finding Text in Files Ergonomically - Announcing recent-rgrep</title><link href="http://yummymelon.com/devnull/finding-text-in-files-ergonomically---announcing-recent-rgrep.html" rel="alternate"/><published>2025-01-17T05:30:00-08:00</published><updated>2025-01-17T05:30:00-08:00</updated><author><name>Charles Choi</name></author><id>tag:yummymelon.com,2025-01-17:/devnull/finding-text-in-files-ergonomically---announcing-recent-rgrep.html</id><summary type="html">&lt;p&gt;Announcing recent-rgrep, a script that reorders recursive grep output by recently modified file, descending.&lt;/p&gt;</summary><content type="html">&lt;p&gt;Searching for text in a directory tree of files is a commonplace task. For people who use plain text files there are a number of tools that can accomplish this. One such tool that is ubiquitous in Unix-flavored (predominantly Linux and macOS) systems is the command line utility &lt;code&gt;grep&lt;/code&gt;. Emacs builds on this with the &lt;code&gt;rgrep&lt;/code&gt; command, invoking &lt;code&gt;grep&lt;/code&gt; recursively and presenting its results in a &lt;code&gt;grep-mode&lt;/code&gt; buffer. In other editors and IDEs, this feature is named “Find in Files” or “Find in Project”.&lt;/p&gt;
&lt;p&gt;Recently I went down the rabbit hole of wanting to get the results of &lt;code&gt;rgrep&lt;/code&gt; but with the following twist: report the match results in order of recently modified file, descending. The implementation I ended up with is a two-pass solution that’s brute force but effective.&lt;/p&gt;
&lt;p&gt;Announcing &lt;a href="https://github.com/kickingvegas/recent-rgrep"&gt;recent-rgrep&lt;/a&gt;, available on GitHub.&lt;/p&gt;
&lt;h1&gt;Features&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Reports matches in order most recently modified files descending (that is, the most recent files are reported first).&lt;/li&gt;
&lt;li&gt;Search only in non-binary files.&lt;/li&gt;
&lt;li&gt;Avoids searching in common SCM directories (&lt;code&gt;.git&lt;/code&gt;, &lt;code&gt;.hg&lt;/code&gt;, &lt;code&gt;.svn&lt;/code&gt;, &lt;code&gt;.cvs&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Uses the existing &lt;code&gt;grep&lt;/code&gt; that you have installed on your system.&lt;/li&gt;
&lt;li&gt;Default search is case-insensitive.&lt;/li&gt;
&lt;li&gt;Supports usage from both the command line and Emacs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;What about ripgrep?&lt;/h1&gt;
&lt;p&gt;NGL, you’re likely better off using &lt;a href="https://github.com/BurntSushi/ripgrep"&gt;ripgrep&lt;/a&gt; if you have it installed. But if not, then this modest script can achieve the desired result described above.&lt;/p&gt;
&lt;h1&gt;Closing Thoughts&lt;/h1&gt;
&lt;p&gt;If this all seems interesting, I invite you to try &lt;code&gt;recent-rgrep&lt;/code&gt; out. In practice, I’ve found it to make my searches more effective as I’m usually more interested in the files that I last worked on. While there’s a performance hit with making two passes, I generally don’t encounter it in the places I use it. YMMV.&lt;/p&gt;</content><category term="misc"/><category term="emacs"/><category term="unix"/></entry><entry><title>Introducing regfmt</title><link href="http://yummymelon.com/devnull/introducing-regfmt.html" rel="alternate"/><published>2022-10-25T11:31:00-07:00</published><updated>2022-10-25T11:31:00-07:00</updated><author><name>Charles Choi</name></author><id>tag:yummymelon.com,2022-10-25:/devnull/introducing-regfmt.html</id><summary type="html">&lt;p&gt;Introducing regfmt - a command line utility to generate SVG diagrams for control register-style data formats&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;img alt="img" src="http://yummymelon.com/images/example_0001-github.svg"&gt;&lt;/p&gt;
&lt;p&gt;Sometimes a project you've had in the mental back burner for decades calls to you again, but this time you pay attention. So it is with &lt;strong&gt;regfmt&lt;/strong&gt;, a command line utility that I spent this past month working on.&lt;/p&gt;
&lt;h2&gt;Backstory&lt;/h2&gt;
&lt;p&gt;While I was in grad school back in the early 1990's the department had prescribed using the AT&amp;amp;T &lt;a href="https://www.troff.org"&gt;troff&lt;/a&gt; tools for writing papers. Among those tools was one called &lt;a href="https://github.com/arnoldrobbins/dformat"&gt;dformat&lt;/a&gt;, which enabled you to easily draw out control register-style data formats using a domain specific language (DSL).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;dformat&lt;/strong&gt; was a great tool for its time but over the years got consigned to bit rot and ultimately forgotten by many. Among the reasons for it being forgotten was that it only supported the &lt;strong&gt;troff&lt;/strong&gt; specific &lt;strong&gt;pic&lt;/strong&gt; drawing language and used a make-shift DSL for its input.&lt;/p&gt;
&lt;h2&gt;Today&lt;/h2&gt;
&lt;p&gt;The world moved on and settled on other tools for writing and drawing. That said, the fundamentals of computer design haven't changed and control registers are still a thing, so the need to draw them out is still a thing, and drawing them by hand is still painful.&lt;/p&gt;
&lt;p&gt;In the intervening time from the early '90s to 2022, I've run into times when I wished I had something like &lt;strong&gt;dformat&lt;/strong&gt; but &lt;em&gt;modern&lt;/em&gt; to use for writing technical documentation. What's modern you say? How about having:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a common vector graphics file format output such as &lt;code&gt;SVG&lt;/code&gt; which can then be easily converted to a raster format (&lt;code&gt;png&lt;/code&gt;, &lt;code&gt;jpg&lt;/code&gt;, etc.).&lt;/li&gt;
&lt;li&gt;an input specification that is based on a common data serialization language.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the early summer of 2022, I got to thinking about &lt;strong&gt;dformat&lt;/strong&gt; and how it could be re-imagined for today and realized wow, all the pieces I needed were there:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;a href="https://en.wikipedia.org/wiki/Scalable_Vector_Graphics"&gt;SVG&lt;/a&gt; for the output format&lt;/li&gt;
&lt;li&gt;Use &lt;a href="https://en.wikipedia.org/wiki/YAML"&gt;YAML&lt;/a&gt; for the input format&lt;/li&gt;
&lt;li&gt;Use &lt;a href="https://en.wikipedia.org/wiki/CSS"&gt;CSS&lt;/a&gt; to style the output&lt;/li&gt;
&lt;li&gt;Implement in &lt;a href="https://www.python.org"&gt;Python&lt;/a&gt; which has support for all of the above.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In October 2022, I found the cycles to go to work on this.&lt;/p&gt;
&lt;h2&gt;Announcing &lt;strong&gt;regfmt&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;regfmt&lt;/strong&gt; is a Python command line utility to generate SVG diagrams for control register-style data formats. It is inspired by the &lt;em&gt;dformat&lt;/em&gt; command from the &lt;em&gt;troff&lt;/em&gt; family of tools, however re-imagined using contemporary (circa 2022) file formats.&lt;/p&gt;
&lt;p&gt;Python installation:
PyPI:  &lt;a href="https://pypi.org/project/regfmt/"&gt;https://pypi.org/project/regfmt/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Source Repository:
GitHub: &lt;a href="https://github.com/kickingvegas/regfmt"&gt;https://github.com/kickingvegas/regfmt&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Example output of &lt;strong&gt;regfmt&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;img alt="img" src="http://yummymelon.com/images/register-stair-left.svg"&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="img" src="http://yummymelon.com/images/register.svg"&gt;&lt;/p&gt;
&lt;h3&gt;Features&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;SVG output&lt;/li&gt;
&lt;li&gt;Modern configuration input file formats&lt;ul&gt;
&lt;li&gt;YAML for register configuration&lt;/li&gt;
&lt;li&gt;CSS for styling SVG output&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Try it out!&lt;/h2&gt;
&lt;p&gt;If you need a tool like this, please take the time to try it out. Any &lt;a href="https://github.com/kickingvegas/regfmt/issues" title="regfmt issue tracker"&gt;feedback&lt;/a&gt; would be appreciated!&lt;/p&gt;
&lt;h3&gt;Requirements&lt;/h3&gt;
&lt;p&gt;Python: ≧ 3.9 &lt;/p&gt;
&lt;h3&gt;Installation&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;regfmt&lt;/strong&gt; supports installation via &lt;a href="https://pypi.org/project/regfmt/"&gt;PyPI&lt;/a&gt;. Is is recommend that you do this in a Python virtual environment. &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;$&lt;span class="w"&gt; &lt;/span&gt;python3&lt;span class="w"&gt; &lt;/span&gt;-m&lt;span class="w"&gt; &lt;/span&gt;venv&lt;span class="w"&gt; &lt;/span&gt;.venv
$&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;source&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;.venv/bin/activate
&lt;span class="o"&gt;(&lt;/span&gt;.venv&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;pip&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;regfmt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</content><category term="misc"/><category term="dev"/><category term="regfmt"/><category term="writing"/><category term="software"/><category term="computer"/><category term="unix"/></entry></feed>