task-logger.sh is a tiny shell lib I wrote about a week ago. It is compatible with
bash and can be used with
sh by just changing the
echo calls (
echo doesn’t accept
It allows to have some fancy output, summarizing what is most important: * execution time * status code
The output is all written to temporary files in
/tmp, making the status of each task easily readable.
ISERT PIC HERE
In my dotfiles I use a quite simple
install.sh script to install everything I need to work. The output isn’t great and I cannot read easily if something fails. This is way I’m moving to task-logger.sh.
During my install script I want to have some critical tasks. However I just want to print messages and then exit instead of
-c option behaviour for
log_cmd. Therefore I implement two functions
They are supposed to be used as a replacement for the
ko function in the
log_cmd <task-name> <task> || ko call.
Most of the translation is pretty much straight forward but sometimes you want to group very tiny tasks such as
mkdir. You can either extend
working functionality to fit your needs or create functions with
|| return 1 at the end of each command. I personally prefer the last one as it produces less output.
For instance backing up files looks like this:
You can even group many
log_cmd inside a function if the tasks are dependants. For example when installing
oh-my-zsh, I need
zsh first. There is no point in installing
zsh already failed. To achieve this we create an other auxiliary function and call it from the main function adding a
|| ko or any other equivalent (
|| return 1 to exit the function. The
|| ok is actually necessary because
log_cmd does print the check mark when the task succeed but doesn’t print anything if it fails. It doesn’t print a newline.
I install Vim plugins with Vundle, inside Vim. This means that Vim is launched and the progress is shown inside. Therefore using
log_cmd is not the right way to go as this will print dots (
.) while in Vim. You should actually use timers and print some custom information. It’s this simple:
In my dotfiles i replace the
ko call with
At the moment I just have this tiny screenshot with a few tasks because most of them are skipped. I will added a better one when I can