Skip to content

Instantly share code, notes, and snippets.

@reinefjord
Created May 24, 2021 15:39
Show Gist options
  • Save reinefjord/cf4b42c9ba8f87a988bc273474d6ef38 to your computer and use it in GitHub Desktop.
Save reinefjord/cf4b42c9ba8f87a988bc273474d6ef38 to your computer and use it in GitHub Desktop.
Adding custom script output to i3status json (output_format = i3bar)
#!/bin/bash
i3status | {
read -r first # read version object
echo "$first" # output version object as is
# read json array stream and collect each element
jq -c --stream --unbuffered 'fromstream(1|truncate_stream(inputs))' | {
# start json array
echo '['
# read each json object (arrays)
while read -r line
do
new=$(ls ~/Mail/account/Inbox/new | wc -l)
mail="{\"name\": \"mail\", \"markup\": \"none\", \"full_text\": \"mail: $new\"}"
# add $mail object in front of array and print
echo "$line" | jq --unbuffered -c --argjson mail "$mail" '[ $mail ] + .'
echo ','
done
echo ']'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment