Pages

September 30, 2015

Bash Scripts for Working With Documentation

Recently I wrote a couple of bash scripts for working with specification documents. They solve sort of general problems, so I decided to share them here.

All scripts can be downloaded from my GitLab repo: gitlab.com/irina-ivanova/scripts

All scripts can be executed in UNIX terminal (for Windows users there are alternatives such as Babun, Cygwin, Cmder). I also recommend to use aliases: just pick up short and unique command, specify the path to the script and you can excecute this script with short command from wherever you are (like spec bug.01.1 for finding specification with such text in the title).


find-specification-by-name.sh
./find-specification-by-name.sh [text_in_file_title]
Script looks for .doc files (extension can be changed) in a specific directory (which can be also changed) where title contains text, that user gives to the script.
In the example I have directory specifications with 4 documents, but only 3 of them contain word bugs in the title. There is also directory Archive with old documents, which script also finds, but shows Archive folder in red, so user can easily differ old documents from new ones (you can also change words that should be colored).

Rows, that you may want to change to use this script in your way:
  • 6 path="/Users/irina/Desktop/specs" – here you should specify the absolute path (not relative, because you want to execute this script from different places) of the directory, where you have all your specifications (usually it's CVS of SVN root directory).
  • 31 find $path -iname "*$text*" | awk -v text="$text" -v lower="$lower" -v upper="$upper" '{ gsub(text, "\033[36m&\033[0m"); gsub(lower, "\033[36m&\033[0m"); gsub(upper, "\033[36m&\033[0m"); gsub("Arhiiv", "\033[31m&\033[0m"); print }' – the awk part is responsible for coloring. Codes like \033[36m are colors – particualary this one means cyan, but you can change it. Also you need to change word "Arhiiv", which helps to differ old documents. Or you can remove this part, if you don't want to color anything.

open-last-specification.sh
./open-last-specification.sh [text_in_file_title]
This one is doing basically the same as the previous one, except that it automatically opens lastly modified file. You can use it, if your components have unique identifiers and specs about these components have many versions, like this:
Rows that you may want to change:
  • 6 path="/Users/irina/Desktop/specs" – same as in the previous one, absolute path to directory with your specs.
  • 43 function checkIsFileIsDoc(){} – in my case I want to open only .doc files – I don't want to open folders or excel files, but you may want to remove this check.

find-text-in-specification.sh
./find-text-in-specification.sh [text_in_the_file_content]
This one is also very similar to first one, only it finds files with given text in the content.
For example, I want to know in which specification is mentioned data base column BUG.STATUS:
Rows that you may need to change are the same as in the first one.

nortal-logo.sh
I always wanted to print some pictures with bash script. So here are my first experiences.
Logo of company where I work. It was picked as easy to reproduce, because it has strict lines.

bug.sh

No comments:

Post a Comment