Anybar - check if a command has finished or didn't
Hey fox, with this post I will start writing in plain English.
Anybar it’s a desktop-app what I have in my arsenal and I have used day by day.
There are versions for linux, windows and Mac.
It’s like a semaphore that you can control, only sending colours to a port.
# Change the colour of an AnyBar
# Usage:
# anybar <colour> <n>
# Change the colour of the n'th AnyBar
# anybar <colour>
# Change the colour of this tab's AnyBar
# anybar
# Change the colour of this tab's AnyBar to white (resetting it)
function anybar() {
local COLOUR=${1-white}
local OFFSET=${2:-$(_anybar_iterm_offset)}
local ANYBAR_PORT=$((1738 + $OFFSET))
echo -n $COLOUR | nc -4u -w0 127.0.0.1 ${ANYBAR_PORT}
}
I used to manage the long execution commands and saw how long it takes:
# Monitor a long-running command using AnyBar
# This sets AnyBar to orange whilst the command is running,
# then to green or red depending on whether the command succeeded or not
#
# Usage:
# alias m=anybar_monitor
# s <some command>
function anybar_monitor() {
if [ $# -eq 0 ]; then
anybar white
else
anybar orange
$@
local EXIT_STATUS=$?
if [ $EXIT_STATUS -ne 0 ]; then
anybar red
else
anybar green
fi
return $EXIT_STATUS
fi
}
With this small snippet I can execute a command and see the status of the command from another desktop screen.
I like the minimalist approach of the command. Because with simple communication you can create an excellent development approach like this:
- After a successful command you can play a sound with voice: “master your command was successful”
- Monitor your local server for development:
while true
do
(echo >/dev/tcp/localhost/"$1") &>/dev/null && anybar blue || anybar exclamation
sleep 1
done
In my case, if the server stop listening it’s because an exception was executed. I need to check the output to see the problem.
Or you can go further:
You can create your anybar strip and control the lights from commands.
https://github.com/htruong/stripbar
and here My guahiro proyect:
https://www.instructables.com/Wireless-Arduino-Traffic-Light/
Who doesn’t want this kind of semaphore when your CI didn’t pass ?