Code


ZSH Arrays and you

So after fighting with zsh for a bit, it seems there is never, ever, a 0 element in zsh arrays. All arrays start populating at element 1 i.e $array[1] Here is some example code to help ya populate and pilfer through an array of elements if its got at least one element: # the following ssh command will return location of each loaded key. for this example, we only have one key loaded.

Continue reading ↦

Taking multline input from a user

So I needed to take in a pasted stdin that was multiple lines. Using just read or any of the flags it provides don’t give a nice clean way to do this. However, using cat and sed, you can provide a few nice ways to allow a user to end the input stream and submit their entry: Ctrl+d: #!/bin/bash echo "Pipe in certificate, or paste and it ctrl-d when done" keyvariable=$(cat) Blank Line:

Continue reading ↦

Re-defining a variable composed of dynamic variables

In one of my scripts, I wanted to create a log file that was dynamic based on how the script was running. For example, if the script was doing something like waiting on another script or generated an error for whatever reason, I wanted the log file name to change to reflect that. I started with this. I used the $STATUS as the switch and called a function (setstatus) to change that based on what was passed (by another function or whatever etc.

Continue reading ↦

I really wanted terminal printing to be in color

Yeah. ccze. is awesome! I really wanted to use it across my systems and with all applicable commands like head, tail, cat, etc.. So I wrote a zsh function to check if the command exists and utilize it. This was kind of a pain because of the corner cases (people using pipes or redirection with the command etc..) Through it all, I created two new commands, catless and tacless. Read some of the comments to find why.

Continue reading ↦