DEV Community

Tea Reggi
Tea Reggi

Posted on

I want a system for organizing shell scripts.

I would love a system for organizing, nesting, documenting, and testing shell scripts. I think about it like a library that can be used with any project you may have in the future.

I'm curious how others organize their shell scripts. I have a shell function called "register" that allows me to document a function after it's declared. This allows me to source a single file and keep adding functions to that file and I get a whole bunch of documentation for free.

# ...other register code

function uri-encode() {
    node -e "console.log(encodeURIComponent('$1'))"
}
register "uri-encode" "<string>" "encodes a string for use in a uri"

function uri-decode() {
    node -e "console.log(decodeURIComponent('$1'))"
}
register "uri-decode" "<string>" "decodes a uri string"

Enter fullscreen mode Exit fullscreen mode

When I run "usage" I get this:

➜  usage 
uri-encode <string>
  encodes a string for use in a uri
uri-decode <string>
  decodes a uri string
Enter fullscreen mode Exit fullscreen mode

This allows me to easily document my shell scripts. I've had other methods in the past for creating subscripts and avoiding collisions. But I'm curious how others manage their scripts, let me know in the comments!

Top comments (0)