jotta / jotta-cli-issues

45 stars 1 forks source link

Feature Request: one-line status for window manager bars #135

Open aerique opened 3 years ago

aerique commented 3 years ago

I would like to have the jotta-cli status in the bar of my window manager (i3status in my case, but it does not matter). Now I have to run jotta-cli status and do cutting and parsing and I still do not get very useful information out of it.

What I mainly would like to see if it is idle or syncing. Just that one word feedback would be nice for now.

Examples of window manager bars:

Kimbsen commented 3 years ago

Thanks for the suggestion. I've added an internal task, but its not high on the priority list right now.

aerique commented 3 years ago

Hi, I've improved my scripts so this in now really low priority for me. For completeness, this is what I use:

$ cat i3status-jottad.sh 
#!/bin/sh

OUT=$(jotta-cli status 2> /dev/null)

COUNT=$(echo "${OUT}"   | grep "Count"   | cut -d: -f 2)
USAGE=$(echo "${OUT}"   | grep "Usage"   | cut -d: -f 2)
UPDATED=$(echo "${OUT}" | grep "Updated" | cut -d: -f 2-4)

# debug for dev
#echo "===\n${OUT}\n===\n"
#echo "===\n${COUNT}\n---\n${USAGE}\n---\n${UPDATED}\n===\n"

if [ "${UPDATED}" = "" ]; then
    #echo -n "syncing"
    echo -n " "  # Nerd font
else
    #echo -n "idle, last update:${UPDATED}"
    echo -n " ${UPDATED}"  # Nerd font
fi
$ cat my-i3status.sh 
#!/bin/sh
# shell script to prepend i3status with more stuff

i3status | while :
do
        read line
        echo "$(i3status-jottad.sh) | $line" || exit 1
done

You can run my-i3status.sh on the commandline, but it is used in ~/.config/i3/config like this:

# Start i3bar to display a workspace bar (plus the system information i3status finds out, if available)
bar {
        font xft:CodeNewRoman Nerd Font
        position top
        #status_command i3status
        status_command exec ~/sync/bin/my-i3status.sh
}

i3bar-example

aerique commented 3 years ago

Now with colors. The scripts are getting really janky now:

$ cat i3status-jottad-json.sh 
#!/bin/sh

OUT=$(jotta-cli status 2>&1)

COUNT=$(echo "${OUT}"        | grep "Count"             | cut -d: -f 2)
DISCONNECTED=$(echo "${OUT}" | grep "Could not connect" | cut -d: -f 2)
USAGE=$(echo "${OUT}"        | grep "Usage"             | cut -d: -f 2)
UPDATED=$(echo "${OUT}"      | grep "Updated"           | cut -d: -f 2-4)

# debug for dev
#echo "===\n${OUT}\n===\n"
#echo "===\n${COUNT}\n---\n${DISCONNECTED}\n---\n${USAGE}\n---\n${UPDATED}\n===\n"

if [ "${DISCONNECTED}" != "" ]; then
    echo -n "{\"name\":\"jottad\", \"color\": \"#cd5c5c\", \"full_text\": \"jottad disconnected \"}"
elif [ "${UPDATED}" = "" ]; then
    echo -n "{\"name\":\"jottad\", \"full_text\": \" ${COUNT} \"}"
else
    echo -n "{\"name\":\"jottad\", \"color\": \"#8fbc8f\", \"full_text\": \" ${UPDATED} \"}"
fi
$ cat my-i3status-json.sh 
#!/bin/sh
# shell script to prepend i3status with more stuff

i3status | while :
do
        read LINE
        if [ "${LINE}" = "{\"version\":1}" ]; then
            echo $LINE
        elif [ $(expr length "${LINE}") = 1 -a "${LINE}" = "[" ]; then
            echo ${LINE}
        elif [ "$(echo ${LINE} | cut -c -1)" = "[" ]; then
            echo "[],"
        else
            echo "[$(i3status-jottad-json.sh),$(echo ${LINE} | cut -c 3-)," || exit 1
        fi
done

i3 config:

bar {
        font xft:CodeNewRoman Nerd Font
        position top
        #status_command i3status
        #status_command exec ~/sync/bin/my-i3status.sh
        status_command exec ~/sync/bin/my-i3status-json.sh
}

i3jotta1 i3jotta2 i3jotta3

coopersimon commented 3 years ago

This is very cool, thanks for sharing :)