Skip to content

Instantly share code, notes, and snippets.

@maccyber
Last active February 4, 2020 22:12
Show Gist options
  • Select an option

  • Save maccyber/d3d69337e3d074d5be710ef14240d657 to your computer and use it in GitHub Desktop.

Select an option

Save maccyber/d3d69337e3d074d5be710ef14240d657 to your computer and use it in GitHub Desktop.

Revisions

  1. maccyber revised this gist Feb 4, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion i3bar-i3cat-leaf.sh
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ display_status() {
    status_text="retrieving info"
    fi

    if [ $charging == "CHARGING" ]; then
    if [ $charging != "NOT_CHARGING" ]; then
    color=#88b090
    icon+=
    fi
  2. maccyber revised this gist Feb 3, 2020. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions i3bar-i3cat-leaf.sh
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    #!/bin/bash

    FILE="/tmp/leaf.log"
    FILE="/tmp/leaf.cache"
    USERNAME=myleaf@leaf.com
    PASSWORD=mypassword

    update_status() {
    result=`leaf-connect-cli cachedStatus -u myleaf@leaf.com -p mypassword -r NE`
    result=`leaf-connect-cli cachedStatus -u $USERNAME -p $PASSWORD -r NE`
    BATTERY_STATUS=`echo ${result} | jq '.BatteryStatusRecords.BatteryStatus.SOC.Value' | sed 's/"//g'`
    CHARGING_STATUS=`echo ${result} | jq '.BatteryStatusRecords.BatteryStatus.BatteryChargingStatus' | sed 's/"//g'`
    echo "$BATTERY_STATUS" > $FILE
  3. maccyber created this gist Feb 3, 2020.
    57 changes: 57 additions & 0 deletions i3bar-i3cat-leaf.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    #!/bin/bash

    FILE="/tmp/leaf.log"

    update_status() {
    result=`leaf-connect-cli cachedStatus -u myleaf@leaf.com -p mypassword -r NE`
    BATTERY_STATUS=`echo ${result} | jq '.BatteryStatusRecords.BatteryStatus.SOC.Value' | sed 's/"//g'`
    CHARGING_STATUS=`echo ${result} | jq '.BatteryStatusRecords.BatteryStatus.BatteryChargingStatus' | sed 's/"//g'`
    echo "$BATTERY_STATUS" > $FILE
    echo "$CHARGING_STATUS" >> $FILE
    }

    display_status() {
    if [ ! -f "$FILE" ]; then
    update_status
    fi

    FILE_TIMESTAMP=$(stat -c %Y $FILE)
    NOW_TIMESTAMP=$(date +"%s")
    DIFF="$(($NOW_TIMESTAMP-$FILE_TIMESTAMP))"

    if [ $DIFF -ge "600" ]; then
    update_status
    fi

    status_text=$(head -n 1 $FILE)
    charging=$(tail -n 1 $FILE)
    icon=

    if [ -z "$status_text" ]; then
    color=#36a8d5
    status_text="retrieving info"
    elif [ $status_text -ge "70" ]; then
    color=#88b090
    status_text="${status_text}%"
    elif [ $status_text -ge "30" ]; then
    color=#ccdc90
    status_text="${status_text}%"
    elif [ $status_text -lt "30" ]; then
    color=#e89393
    status_text="${status_text}%"
    else
    color=#36a8d5
    status_text="retrieving info"
    fi

    if [ $charging == "CHARGING" ]; then
    color=#88b090
    icon+=
    fi

    echo '[{"name": "leaf", "instance": "battery", "full_text": " '${icon}' ' ${status_text} '", "color": "'${color}'"}]'
    }

    while sleep 10; do
    display_status
    done