Skip to content

Instantly share code, notes, and snippets.

@rosenpin
Last active November 6, 2021 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosenpin/f566917abe867758e334af99815e9dad to your computer and use it in GitHub Desktop.
Save rosenpin/f566917abe867758e334af99815e9dad to your computer and use it in GitHub Desktop.
A wrapper script for i3-agenda used to show the output in SwiftBar.
#!/bin/bash
# <swiftbar.hideAbout>true</swiftbar.hideAbout>
# <swiftbar.hideRunInTerminal>true</swiftbar.hideRunInTerminal>
# <swiftbar.hideLastUpdated>true</swiftbar.hideLastUpdated>
# <swiftbar.hideDisablePlugin>true</swiftbar.hideDisablePlugin>
# max attempts count
max_attempts=5
# number of lines to interpret as error message
error_threshold=5
error_counter=0
run-command(){
output="$($@ 2>&1)"
if [[ $(echo "$output" | wc -l) -gt $error_threshold ]]; then
# retry every 15 seconds for max_attempts times
if [[ $error_counter -lt $max_attempts ]]; then
sleep 15
((error_counter++))
run-command $@
else
echo "error"
export error_msg="$output"
fi
else
echo "$output"
fi
}
run-command ~/bin/agenda
echo "---"
href="href='https://calendar.google.com/calendar/u/0/r/'"
i=1
while :; do
event=$(run-command /usr/local/bin/python $HOME/Projects/i3-agenda/i3_agenda/__init__.py -c $HOME/.i3agenda/client.json -ttl 30 --limchar 30 --skip $i --today | pybidi)
((i++))
if [[ "$event" == "No events" ]]; then
exit 0
fi
if [[ "$event" == "error" ]]; then
echo "$error_msg"
exit 1
fi
echo "$event | $href"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment