Friday, September 18, 2020

Bring Some Color to Your bash Shell Output

I'm not sure if this is something anyone will find valuable but it's been a neat little addition to my scripting as of late.

For those who have used Cucumber in the past for BDD, one of the visible elements is of course there paradigm of green, yellow and red text that appears for a variety of things in your output on the screen. This division also helps me quickly monitor if something seems out of place or if a command I expect to run completes correctly or not. as I do a lot with shell scripts, I decided to do some research and see if I could add a bit of that green, yellow, red (and for some variety I even added blue to the mix). Here's how you can do that.

First, the echo command allows for ANSI escape codes to be called and change the color of text. To do this, you first call echo with the '-e' flag and then for the word or words you want to highlight with a different color. You can see a list of ANSI escape codes and colors here. For my purposes, here's an example of a set of codes I keep is a shared shell library:


In practice, any time you use an echo -e statement, you can determine if the output you see is normal/expected, if it's an error, if it's a possible warning that doesn't rise to the level of an error, or if you want to display some information that fits some other purpose. Also, once you set a color, that color will remain in place unless you reset back to the default color option.

In practice it looks like this:

if [ $# -lt 5 ] ; then
   echo -e "${RED}Usage: $0 [CUSTOMER] [DUNS] [VERSION] [TEST_TYPE] [filename] ${RESET}"
    exit 1

if [[ "${TEST_TYPE}" = "ZIP" ]] ; then
echo -e "${GREEN}Creating an initial ZIP archive${RESET}"
/c/Program\ Files/7-Zip/7z.exe a -r ./ 001-EmptyFile.txt

Note that the plain text is the output of the command itself, the green text is my own message text to alert me that everything is running as expected or to see if something isn't working how I want to.

For each echo statement or set of statements you want to print out, you can set the color with an escape code, and then you can have that text be formatted as you see fit, anywhere from a single word to an entire line. You do need to end your statement with a RESET code to go back to regular output.

In any event, it's something I've found useful, I figured some of you might, too :).

Thursday, September 17, 2020

Coming to PNSQC in October: Add Some Accessibility to Your Day

 First off... Hello again, Hello!

Where have I been? Many places and no place whatsoever. that seems to be the story of 2020 for many. I wanted to be inspiring. I wanted to write. I wanted to do a lot of things. Ultimately, I kept hoping each day would get better and there would be something more for me to discuss or focus on. I have a podcast I produce regularly, and we are back to two episodes a month. I've focused on a change to a new workgroup and a new focus. My eldest daughter is doing cosmetology school online and we are "office mates" in the sense that she is doing her classes in the family room just outside my office. Other than those, every day is pretty similar. I wake up, I work, I doa few things, I stay close to home, I keep my interactions with others to a distant minimum. Rinse and repeat.

Regardless, one doesn't change something if they just sit still and tread water, so let's break this quiet period and get back into the swing of things. What better way to do that than some good old fashioned shameless self-promotion ;)?

I will be giving a workshop at the Pacific Northwest Software Quality Conference on October 14, 2020. This conference, due to the changes in gathering and groups in close proximity, is going to be virtual. I will confess, I'm a little anxious about this because I'm used to workshops having a give and take and me communicating with people directly. How much of this will we be able to do remains to be seen. Nevertheless, I am happy to take on the challenge.

My workshop will be titled "Add Some Accessibility to Your Day" and it is a beginner-friendly approach to looking at and focusing on real Accessibility testing that people can do every day with a handful of tools, a focus on looking at a variety of scenarios and a site that will allow us to look at Before and After examples of Accessibility features present and absent. Also, this year, the workshops are included in the price of the conference, ab=nd the conference is considerably less expensive due to the virtual format. 

The trailer for the workshop can be seen here:

Also, another thing to mention... I have launched the TESTHEAD YouTube channel. At the moment, this video is it but there will be more to come in the coming days and weeks. Please feel free to Like and Subscribe and all that :).