Last active
March 5, 2016 22:47
-
-
Save michaelward82/c1903f2b37a76975740e to your computer and use it in GitHub Desktop.
Helper function to create prettier and more meaningful vagrant provisioning script output. https://github.com/michaelward82/vagrant-provisioning-shell-function-helper for project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exe () { | |
| MESSAGE_PREFIX="\b\b\b\b\b\b\b\b\b\b" | |
| echo -e "$MESSAGE_PREFIX Execute: $1" | |
| LOOP=0 | |
| while true; | |
| do | |
| if ! [ $LOOP == 0 ]; then echo -e "$MESSAGE_PREFIX ... "; fi; | |
| sleep 3; | |
| LOOP=$((LOOP+1)) | |
| done & ERROR=$("${@:2}" 2>&1) | |
| status=$? | |
| kill $!; trap 'kill $!' SIGTERM | |
| if [ $status -ne 0 ]; | |
| then | |
| echo -e "$MESSAGE_PREFIX ✖ Error" >&2 | |
| echo -e "$ERROR" >&2 | |
| else | |
| echo -e "$MESSAGE_PREFIX ✔ Success" | |
| fi | |
| return $status | |
| } | |
| # Use as: | |
| # exe "Update apt indexes" sudo apt-get update | |
| # exe "Disable default vhost" sudo a2dissite 000-default | |
| # | |
| # Output: | |
| # | |
| # ==> Execute: Update apt indexes | |
| # ==> ... | |
| # ==> ... | |
| # ==> ... | |
| # ==> ✔ Success | |
| # ==> Execute: Disable default vhost | |
| # ==> ✔ Success |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output using exe function, with no errors:

Example output using exe function, with error:

Default output from executing commands directly, no actual errors:
