Protip: an extremely simple method of managing & finding & deploying all your little utility shell scripts…

reddit

I've been a Linux/Unix sysadmin since the 90s, and I really wish I'd thought of this sooner. The idea popped in my head a couple of years ago, and since then I've been really happy with how much it's simplified all this stuff.

The problems:

  • When you have lots of little shell scripts, it can be easy to forget what their names are and lose track of them (both their names + dirs).
  • For anyone dealing with multiple systems + user accounts, while I'm sure there's some cool systems out there to manage and deploy them to all your other hosts, it really doesn't need to be very complicated.
  • Putting them under /usr/local/bin, or especially anywhere else like a custom dir you've made yourself means they aren't always in $PATH 100% of the time, of course you can edit the global shell profile scripts etc, but I've found there's always edge cases that get missed.

My super simple solution to all of this:

  • All my scripts start with a prefix sss- – this means they're super easy to find, and I can type sss (using the same letter, and on the left-side of the keyboard makes this very fast) and then hit tab in a shell to see the list of all my scripts, without anything else (scripts/binaries not created by myself) being included at all
  • I gave up on putting them in /usr/local/bin/ (or elsewhere) and trying to ensure $PATH always included it for all users/cron/other methods of starting programs from inside other apps etc, and now they always just go directly in /usr/bin – now they are always in $PATH 100% of the time, and I don't have to think about that shit ever again.
    • A common (and reasonable) reason that people don't like putting them in /usr/bin is because they get lost with everything else, but the sss- prefix completely solves that, it's 100% clear what I put there, and I can easily just rm /usr/bin/sss-* at any time without worrying about breaking anything else.
  • My deployment script that pushes them out to all hosts is very simple:
    • first run: rm /usr/bin/sss-* on the destinations
    • then rsync them all back there again, that way old removed scripts get deleted, and everything else is always current
  • I've also stopped adding filename extensions like .sh – this way if I ever rewrite the script into another language in the future, the name can stay the same without breaking all the other stuff that might call it
  • I use the same convention on Windows too for batch + powershell files… if I want to find all my scripts on any system or OS, I can simply do a global file search for sss- and find them all immediately without any false positives in the results
  • Likewise for searching the content of code/scripts in my editor, I can just search for the sss- string, and find 100% of calls to all my own custom scripts instantly
  • Also for a lot of stuff that I used to use bash aliases for, I'm now just writing a small script instead… the benefit to this is that when I push the scripts out, I don't need to login again to be able to find/use them

An unexpected bonus benefit to all this has been that due to how ergonomic and easy it is to manage them all now, I'm now creating so many more scripts to begin with.

When stuff is easy to do (and doesn't require as many decisions on trivial naming/location things), you're more likely to do it more often.

submitted by /u/r0ck0
[link] [comments]