Initial commit - statusbar - Shell script to set/print a status bar
 (HTM) hg clone https://bitbucket.org/iamleot/statusbar
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) changeset 515364f6849d4f1ea721b58c98d3d368a7c587ae
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Tue, 27 Feb 2018 14:17:46 
       
       Initial commit
       
       Diffstat:
        statusbar.sh |  221 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        1 files changed, 221 insertions(+), 0 deletions(-)
       ---
       diff -r 000000000000 -r 515364f6849d statusbar.sh
       --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
       +++ b/statusbar.sh      Tue Feb 27 14:17:46 2018 +0100
       @@ -0,0 +1,221 @@
       +#!/bin/sh
       +
       +#
       +# Copyright (c) 2018 Leonardo Taccari
       +# All rights reserved.
       +# 
       +# Redistribution and use in source and binary forms, with or without
       +# modification, are permitted provided that the following conditions
       +# are met:
       +# 
       +# 1. Redistributions of source code must retain the above copyright
       +#    notice, this list of conditions and the following disclaimer.
       +# 2. Redistributions in binary form must reproduce the above copyright
       +#    notice, this list of conditions and the following disclaimer in the
       +#    documentation and/or other materials provided with the distribution.
       +# 
       +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
       +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
       +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
       +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
       +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
       +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
       +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
       +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       +# POSSIBILITY OF SUCH DAMAGE.
       +#
       +
       +
       +#
       +# Customizable variables used by the various functions.
       +#
       +acad_sensor="${STATUSBAR_ACAD_SENSOR}"
       +battery_sensor="${STATUSBAR_BATTERY_SENSOR}"
       +clock_format="${STATUSBAR_CLOCK_FORMAT}"
       +date_format="${STATUSBAR_DATE_FORMAT}"
       +mixer_mute="${STATUSBAR_MIXER_MUTE}"
       +mixer_output="${STATUSBAR_MIXER_OUTPUT}"
       +network_interfaces="${STATUSBAR_NETWORK_INTERFACES}"
       +temperature_sensor="${STATUSBAR_TEMPERATURE_SENSOR}"
       +
       +#
       +# Customizable status command dynamically evaluated every $sleep_time.
       +#
       +status_cmd='status="`network_status` $separator `volume` $separator `cpu_temperature` $separator `battery_status` $separator `unread_mail` $separator `unread_feeds` $separator `what_day_is_it` $separator `what_time_is_it`"'
       +
       +# Sleep time (in seconds) used to refresh the status bar
       +sleep_time=60
       +
       +#
       +# Symbols (mostly Unicode characters) used by the various functions.
       +#
       +acad_symbol="🔌"
       +battery_symbol="🔋"
       +clock_symbol="⏰"
       +date_symbol="📅"
       +mail_symbol="🖂"
       +network_symbol="🖧"
       +feeds_symbol="📰"
       +temperature_symbol="🌡"
       +separator="|"
       +
       +mute_volume_symbol="🔇"
       +low_volume_symbol="🔈"
       +medium_volume_symbol=" 🔉"
       +high_volume_symbol="🔊"
       +
       +
       +#
       +# Print current date via date(1) honoring $date_format.
       +#
       +what_day_is_it()
       +{
       +       printf "%s " $date_symbol
       +       date "$date_format"
       +}
       +
       +#
       +# Print current time via date(1) honoring $clock_format.
       +#
       +what_time_is_it()
       +{
       +       printf "%s " $clock_symbol
       +       date "$clock_format"
       +}
       +
       +#
       +# Print the number of unread emails.
       +# FIXME: nmh logic is actually hardcoded inside the function.
       +#
       +unread_mail()
       +{
       +       printf "%s " $mail_symbol
       +       new | sed -nE '/total/ s/^ total +([0-9]+)\.$/\1/p'
       +}
       +
       +#
       +# Print the number of unread feeds.
       +# FIXME: nmh logic is actually hardcoded inside the function.
       +#
       +unread_feeds()
       +{
       +       printf "%s " $feeds_symbol
       +       MH=${HOME}/.mh_rss_profile new | sed -nE '/total/ s/^ total +([0-9]+)\.$/\1/p'
       +}
       +
       +#
       +# Print the percentage of battery left using envstat(8) and $battery_sensor.
       +# If an AC adapter is present set the AC adapter symbol accordingly.
       +#
       +battery_status()
       +{
       +       acad_connected=`envstat -s "$acad_sensor" | awk '/connected:/ { print $2 }'`
       +
       +       if [ "$acad_connected" = "TRUE" ]; then
       +               printf "%s " $acad_symbol
       +       else
       +               printf "%s " $battery_symbol
       +       fi
       +       { envstat -s "$battery_sensor" || echo "charge: (N/A)" ; } | sed -e 's/\.[0-9][0-9]%/%/' -nEe '/charge:/ s/^.*\(([^)]+)\)$/\1/p'
       +}
       +
       +#
       +# Print all the network interfaces currently up defined in
       +# $network_interfaces list.
       +#
       +network_status()
       +{
       +       connected=""
       +
       +       printf "%s " ${network_symbol}
       +       for i in $network_interfaces; do
       +               if [ -n "`ifconfig -u $i 2>/dev/null`" ]; then
       +                       if [ ! "$connected" ]; then
       +                               connected="yes"
       +                       fi
       +                       printf " ${i}"
       +               fi
       +       done
       +
       +       if [ ! "$connected" ]; then
       +               printf " -"
       +       fi
       +}
       +
       +#
       +# Print the CPU temperature using envstat(8) and $temperature_sensor.
       +#
       +cpu_temperature()
       +{
       +       printf "%s " $temperature_symbol
       +       { envstat -s "$temperature_sensor" || echo "temperature: N/A" ; } | sed -nE '/temperature:/ s/^.*: *([0-9]+|N\/A) *.*$/\1/p'
       +}
       +
       +#
       +# Print current volume level graphically via a symbol using mixerctl(1) and
       +# $mixer_output.
       +#
       +volume()
       +{
       +       low_volume=0
       +       medium_volume=80
       +       high_volume=160
       +
       +       if [ "$mixer_mute" -a "`mixerctl -n $mixer_mute 2>/dev/null`" = "on" ]; then
       +               echo "$mute_volume_symbol"
       +               return
       +       fi
       +
       +       volume=`mixerctl -n "$mixer_output" | awk -F ',' '{ print ($1 + $2) / 2 }'`
       +
       +       if [ $volume -le $low_volume ]; then
       +               echo "$low_volume_symbol"
       +       elif [ $volume -le $medium_volume ]; then
       +               echo "$medium_volume_symbol"
       +       else
       +               echo "$high_volume_symbol"
       +       fi
       +}
       +
       +onetime=false
       +output=false
       +
       +args=`getopt 1os: $*`
       +if [ $? -ne 0 ]; then
       +       echo "usage: $0 [-1o] [-s seconds]"
       +       exit 2
       +fi
       +set -- $args
       +while [ $# -gt 0 ]; do
       +       case "$1" in
       +       -1)
       +               onetime=true
       +               ;;
       +       -o)
       +               output=true
       +               ;;
       +       -s)
       +               sleep_time=$2; shift
       +               ;;
       +       --)
       +               shift; break
       +               ;;
       +       esac
       +       shift
       +done
       +
       +while true; do
       +       eval $status_cmd
       +       if $output; then
       +               printf "\r"
       +               printf "%s" "$status"
       +       else
       +               xsetroot -name "$status"
       +       fi
       +       if $onetime; then
       +               exit 0
       +       fi
       +       sleep $sleep_time
       +done