Bonus Drop #40 (2024-02-12): What The Shell?

Nish; await; slugify

We focus on two shell utilities and one “super” shell in today’s Bonus edition.

TL;DR

(This is an AI-generated summary of today’s edition.)

(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.)

  • 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.
  • 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.
  • 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.

Nish

Photo by Alan Cabello on Pexels.com

(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.)

Nish (GH) 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.

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.

The author describes it as a mix of Atuin and DirEnv, and this is somewhat appropro, given that you actually interact with the shell you started in (hence, me calling it a “super” shell).

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.

As noted, it’s based on Nim, a language we don’t tap into much in the Drop. You can use Rosetta Code to see what Nim looks like in comparison to other languages.

await

Photo by samer daboul on Pexels.com

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.

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 await (GH). 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”.

Some examples it provides include:

# action on specific file type changes
wait 'stat **.c' --change --forever --exec 'gcc *.c -o await -lpthread'

# waiting google (or your internet connection) to fail
await '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 to
await 'socat -u OPEN:/dev/null UNIX-CONNECT:/tmp/redis.sock' --exec 'redis-cli -s /tmp/redis.sock'

# lazy version
await 'ls /tmp/redis.sock'; redis-cli -s /tmp/redis.sock

# daily checking if I am on french reviera. Just in case
await 'curl https://ipapi.co/json 2>/dev/null | jq .city | grep Nice' --interval 86400

# Yet another server monitor
await "curl 'https://whatnot.ai' &>/dev/null && echo 'UP' || echo 'DOWN'" --forever --change\
    --exec "ntfy send \'whatnot.ai \1\'"

# waiting for new iPhone in daemon mode
await 'curl "https://www.apple.com/iphone/" -s | pup ".hero-eyebrow text{}" | grep -v 12'\
 --change --interval 86400 --daemon --exec "ntfy send \1"

I find it especially handy when waiting on Athena queries to finish.

slugify

Photo by Pixabay on Pexels.com

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 slugify bash script comes in handy.

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.

FIN

Remember, you can follow and interact with the full text of The Daily Drop’s free posts on Mastodon via @dailydrop.hrbrmstr.dev@dailydrop.hrbrmstr.dev ☮️

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.