Skip to content

Instantly share code, notes, and snippets.

@terrbear
Created January 3, 2018 21:09
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 terrbear/cefba97301192a162c7d47498d510ccb to your computer and use it in GitHub Desktop.
Save terrbear/cefba97301192a162c7d47498d510ccb to your computer and use it in GitHub Desktop.
function ps1_bgl {
source ~/.nightscout/info.sh
local RED="$(tput setaf 1 2>/dev/null || echo '')"
local GREEN="$(tput setaf 2 2>/dev/null || echo '')"
local YELLOW="$(tput setaf 3 2>/dev/null || echo '')"
local NO_COLOR="$(tput sgr0 2>/dev/null || echo '')"
local trend="?"
case ${nightscout_trend} in
DoubleUp) trend="⇈";;
SingleUp) trend="↑";;
FortyFiveUp) trend="↗";;
Flat) trend="→";;
FortyFiveDown) trend="↘";;
SingleDown) trend="↓";;
DoubleDown) trend="⇊";;
esac
if [ "${nightscout_bgl}" -ge "180" ]; then
printf "\001${YELLOW}\002"
elif [ "${nightscout_bgl}" -le "80" ]; then
printf "\001${RED}\002"
else
printf "\001${GREEN}\002"
fi
printf "%03d %s" "${nightscout_bgl}" "${trend}"
printf "\001${NO_COLOR}\002"
}
#!/bin/bash
mkdir -p ~/.nightscout
curl http://www.mayabetes.org/api/v1/entries.json > ~/.nightscout/current.json
rm -f ~/.nightscout/info.sh
echo "export nightscout_bgl=$(cat ~/.nightscout/current.json | /usr/local/bin/jq .[0].sgv)" > ~/.nightscout/info.sh
echo "export nightscout_trend=$(cat ~/.nightscout/current.json | /usr/local/bin/jq .[0].direction)" >> ~/.nightscout/info.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment