0

Is it possible to be able to enter foo and have bash automatically convert it to time foo && notify-send "PLAYBOOK COMPLETE"?

I'd specifically like this to apply only to ansible-playbook commands (for those not familiar with Ansible, any number of options, arguments etc. might follow ansible-playbook so a simple alias probably won't do the trick) so that I get notified when a long playbook has finished.

A command before every bash command looked promising, but unfortunately didn't work correctly for me.

Sam
  • 180
  • 2
  • 10

1 Answers1

1

With a shell function:

function ansible-playbook { time command ansible-playbook "$@" && notify-send "PLAYBOOK COMPLETE"; }

or

ansible-playbook () { time command ansible-playbook "$@" && notify-send "PLAYBOOK COMPLETE"; }

The latter form is the POSIX way to define a function but ansible-playbook alias (if any) may interfere. The former form is immune but not portable. If there is no alias and you're using Bash then either form will work.

Or you can write a wrapper script that works in a similar way. If you name it ansible-playbook then make sure it calls the real ansible-playbook, not itself. In the above function the word command prevents calling the function itself in an infinite loop.