hrbrmstr's Daily Drop<p><strong>Nish; await; slugify</strong></p><p>We focus on two shell utilities and one “super” shell in today’s Bonus edition.</p> <p><a href="https://dailydrop.hrbrmstr.dev/?post_type=post&p=139502511" rel="nofollow noopener" target="_blank">Subscribe</a></p> <p><strong>TL;DR</strong></p><p><em>(This is an AI-generated summary of today’s edition.)</em></p><p><em>(Could not for the life of me get it to produce links today…I think there’s some tweaking going on to compete with Gemini.)</em></p><ul><li>The blog post discusses “Nish”, a new, non-POSIX, multiplatform command-line “super” shell currently in the beta stage. Nish offers features such as tab completion, syntax highlighting, variables, aliases, and a database to store all shell-related data. It also supports advanced shell commands’ history manipulation, global and local environment variables, plugins, an advanced help system, and more. The author describes it as a mix of Atuin and DirEnv. Nish is based on Nim, a language not commonly used in the Drop.</li><li>The post also introduces “await”, a C-based tool designed to run a list of commands in parallel and wait for their termination. It provides examples of how to use await in various scenarios, such as waiting for specific file type changes, waiting for a website to fail, and checking if the user is in a specific location.</li><li>Lastly, the post mentions “slugify”, a bash script by Ben Linton that is useful for renaming files and directories with spaces and underscores in their names. The author finds it especially handy for dealing with files named with spaces and underscores, which they find uncivilized.</li></ul> <p><strong>Nish</strong></p><p></p>Photo by Alan Cabello on <a href="https://www.pexels.com/photo/grey-conch-shell-on-shore-917486/" rel="nofollow noopener" target="_blank">Pexels.com</a><p>(If you’re “anti-Nim” due to some comments from the primary developer/maintainer of this nascent language, def move on to the other two sections.)</p><p><a href="https://forum.nim-lang.org/t/10975" rel="nofollow noopener" target="_blank">Nish</a> (<a href="https://github.com/thindil/nish" rel="nofollow noopener" target="_blank">GH</a>) is a new, non-POSIX, multiplatform command-line “super” shell, similar to zsh, bash, or fish, currently in the beta stage. It offers features such as tab completion, syntax highlighting, variables, aliases, and a (SQLite) database to store all shell-related data. This includes configuration, history, variables, and aliases, which enabled features such as searching through CLI history in more advanced ways than with existing shells.</p><p>It also supports global and local aliases, advanced shell commands and shell configuration, history manipulation, global/local environment variables, and plugins. More features include a new take on a help system, syntax highlighting for entered commands (based on validity), and suggestions for commands when one enters an unknown command. Extra features also include setting the terminal title, a theming system, and the ability to execute commands with or without the system’s default shell (which nish runs atop of). It also allows for setting the precision of suggestions and disabling/enabling various features through the shell’s options.</p><p>The author describes it as a mix of <a href="https://github.com/atuinsh/atuin" rel="nofollow noopener" target="_blank">Atuin</a> and <a href="https://github.com/direnv/direnv" rel="nofollow noopener" target="_blank">DirEnv</a>, and this is somewhat appropro, given that you actually interact with the shell you started in (hence, me calling it a “super” shell).</p><p>I verified that it works on Linux and doesn’t do anything skeezy, but I won’t have time to put it through any paces for a while.</p><p>As noted, it’s based on <a href="https://nim-lang.org/" rel="nofollow noopener" target="_blank">Nim</a>, a language we don’t tap into much in the Drop. You can use <a href="https://rosettacode.org/wiki/Category:Nim" rel="nofollow noopener" target="_blank">Rosetta Code</a> to see what Nim looks like in comparison to other languages.</p><p><strong>await</strong></p><p></p>Photo by samer daboul on <a href="https://www.pexels.com/photo/person-holding-hour-glass-1209999/" rel="nofollow noopener" target="_blank">Pexels.com</a><p>Asynchronous operations have been part of computing since the early days, and we spend a great deal of time in async-land when working in both client and server programming operations.</p><p>There are occasions where you need to spawn a bunch of commands and wait for them all to finish before continuing on with some other operation. There are (IMO clunky) ways to do this in various shells, but that can all be abstracted away with <a href="https://await-cli.app/" rel="nofollow noopener" target="_blank"><code>await</code></a> (<a href="https://github.com/slavaGanzin/await" rel="nofollow noopener" target="_blank">GH</a>). It’s a spiffy little C-based tool that’s designed to run a list of commands in parallel and wait for their termination. The footprint is super-small (28K!), and it “just works”.</p><p>Some examples it provides include:</p> <pre># action on specific file type changeswait 'stat **.c' --change --forever --exec 'gcc *.c -o await -lpthread'# waiting google (or your internet connection) to failawait 'curl google.com' --fail# waiting only google to fail (https://ec.haxx.se/usingcurl/usingcurl-returns)await 'curl google.com' --status 7# waits for redis socket and then connects toawait 'socat -u OPEN:/dev/null UNIX-CONNECT:/tmp/redis.sock' --exec 'redis-cli -s /tmp/redis.sock'# lazy versionawait 'ls /tmp/redis.sock'; redis-cli -s /tmp/redis.sock# daily checking if I am on french reviera. Just in caseawait 'curl https://ipapi.co/json 2>/dev/null | jq .city | grep Nice' --interval 86400# Yet another server monitorawait "curl 'https://whatnot.ai' &>/dev/null && echo 'UP' || echo 'DOWN'" --forever --change\ --exec "ntfy send \'whatnot.ai \1\'"# waiting for new iPhone in daemon modeawait 'curl "https://www.apple.com/iphone/" -s | pup ".hero-eyebrow text{}" | grep -v 12'\ --change --interval 86400 --daemon --exec "ntfy send \1"</pre> <p>I find it especially handy when waiting on Athena queries to finish.</p><p><strong>slugify</strong></p><p></p>Photo by Pixabay on <a href="https://www.pexels.com/photo/slug-158158/" rel="nofollow noopener" target="_blank">Pexels.com</a><p>I despise file and directory names with spaces and underscores in them. On top of that, I also have need to turn spaced words into “slugs” in various contexts, including shell scripts. I try to avoid relying on external programs in shell scripts, especially ones that are not generally, universally installed. Hence, Ben Linton’s <a href="https://github.com/benlinton/slugify" rel="nofollow noopener" target="_blank">slugify</a> bash script comes in handy.</p><p>It’s especially handy if you have a directory tree with files named by a monster of a human who uses spaces and worse in file/directory names. One run of the program, and they’re all renamed to something more civilized.</p> <p><a href="https://dailydrop.hrbrmstr.dev/?post_type=post&p=139502511" rel="nofollow noopener" target="_blank">Subscribe</a></p> <p><strong>FIN</strong></p><p>Remember, you can follow and interact with the full text of The Daily Drop’s free posts on Mastodon via <code>@dailydrop.hrbrmstr.dev@dailydrop.hrbrmstr.dev</code> ☮️</p><p><a href="https://dailydrop.hrbrmstr.dev/2024/02/12/bonus-drop-40-2024-02-12-what-the-shell/" rel="nofollow noopener" target="_blank">https://dailydrop.hrbrmstr.dev/2024/02/12/bonus-drop-40-2024-02-12-what-the-shell/</a></p><p><a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://dailydrop.hrbrmstr.dev/tag/async/" target="_blank">#async</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://dailydrop.hrbrmstr.dev/tag/await/" target="_blank">#await</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://dailydrop.hrbrmstr.dev/tag/bash/" target="_blank">#bash</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://dailydrop.hrbrmstr.dev/tag/ksh/" target="_blank">#ksh</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://dailydrop.hrbrmstr.dev/tag/nim/" target="_blank">#nim</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://dailydrop.hrbrmstr.dev/tag/parallel/" target="_blank">#parallel</a> <a rel="nofollow noopener" class="hashtag u-tag u-category" href="https://dailydrop.hrbrmstr.dev/tag/shell/" target="_blank">#shell</a></p>