1. 28

Credits to @nerdypepper for squashing some bugs and implementing some cool features.

    1. 7

      This turned out nice. I might send a PR or two your way to . :-)

      It shouldn’t be difficult at all to port this to POSIX shell too.

    2. 4

      Haha, I did exactly this, minus the coloring for a presentation to a client. I only had an SSH access to my machine and was demoing CLI tools, so was too lazy to change context (and was able to have the slides stay into a corner of the screen with the tool taking the other side).

      Without much formatting, the script itself is very short, it was fun. Not sure the client was impressed however! But the presentation went well (at least the product was exceeding expectations).

      I’m not sure there are many reasons to do it in bash instead of POSIX shell however? Only thing lacking might be local variables in functions, but many shell still implement them.

      1. 3

        Local variables (or more specifically the ‘local’ keyword) can be mimicked in POSIX shell by wrapping the code in ( ) with the expense of a sub-shell.


            printf '%s\n' "$var"
        # '$var' will be unset.
        printf '%s\n' "$var"

        I also sometimes do this with functions themselves.

        func() (
            # code here.

        (Notice how ‘()’ is used in place of ‘{}’ for the function body).

      2. 2

        Interesting! I’m planning to use this in a talk I’m giving this weekend. Let’s see how that goes. :D

        I’m not sure there are many reasons to do it in bash instead of POSIX shell however?

        I use bash interactively and am fairly comfortable with its features; mapfile etc. are pretty nifty. Shouldn’t be too hard to port it to POSIX sh though—I just might.

    3. 2

      In the immortal words of Dr. Ian Malcolm, “Your scientists were so preoccupied with whether or not they could, they didn’t stop to think if they should.”

    4. 1

      You may want to consider envsubst. proably better fits the model you’re trying to achieve with this line anyhow.

    5. 1

      This is SO cool!