sb

simple bar for dwm
git clone git://git.ckyln.com/sb.git
Log | Files | Refs | README | LICENSE

sb (1688B)


      1 #!/usr/bin/env sh
      2 # See the LICENSE file for copyright and license details.
      3 
      4 FUNCPATH="./func"
      5 VERSION="git"
      6 
      7 usage() {
      8 	cat <<EOF
      9 ${0##*/} [options]
     10 
     11   Options:
     12     -d      Use the default configuration
     13     -n      Print to stdout instead of the bar
     14     -x      Kill existing sb instance
     15     -h      Print this help and exit
     16     -v      Print version number and exit
     17 
     18 ${0##*/}-$VERSION
     19 2019-2020 (c) Cem Keylan
     20 EOF
     21 exit 1
     22 }
     23 
     24 while [ "$1" ] ; do case "$1" in 
     25     -d) noconfig=1 ; shift ;;
     26     -v) printf '%s\n' "${0##*/}-$VERSION"; exit 0 ;; 
     27     -n) nobar=1 ; shift ;; 
     28     -x) ! [ -e "/tmp/sb-$USER.pid" ] && \
     29     	printf "There is no running instance of sb\\n" && exit 1
     30     kill "$(cat "/tmp/sb-$USER.pid")"; rm "/tmp/sb-$USER.pid"; exit 0 
     31     ;; 
     32     *) usage ;;
     33 esac ; done
     34 
     35 
     36 [ "$noconfig" ] || { [ -e "$HOME/.config/sbrc" ] && . "$HOME/.config/sbrc" ;}
     37 [ "$DELIMITER" ] || DELIMITER="|"
     38 [ "$SLEEPTIME" ] || SLEEPTIME="1"
     39 
     40 # Load Functions
     41 for func in "$FUNCPATH/"* ; do [ -f "$func" ] && . "$func"; done
     42 for func in "$HOME/.config/sb-func/"* ; do [ -f "$func" ] && . "$func" ; done
     43 
     44 # Unless running from the command line, check for
     45 # an existing instance
     46 [ "$nobar" ] || { [ -e "/tmp/sb-$USER.pid" ] && {
     47 	[ -z "$KILLEXISTING" ] && printf 'ERROR: sb is already running\nIf you think otherwise, remove /tmp/sb-%s$.pid manually.\n' "$USER" && exit 1
     48 	kill "$(cat "/tmp/sb-$USER.pid")" 2>/dev/null ;}
     49 	printf '%s\n' "$$" > "/tmp/sb-$USER.pid" ;}
     50 
     51 command -v bar >/dev/null 2>&1 || bar() { storage ; ram ; gethostname ; datetime ;}
     52 
     53 [ -z "$nobar" ] && while true; do xsetroot -name " $(bar)"; sleep "$SLEEPTIME"; done && exit 0
     54 while true; do clear ; bar; sleep "$SLEEPTIME"; done