#!/bin/sh # osd-msg --- show text or percentage message onscreen # Author: Noah Friedman # Created: 2010-10-02 # Public domain # $Id: osd-msg,v 1.3 2016/01/11 08:47:50 friedman Exp $ kill_prior() { if [ -f $pidfile ]; then read pid < $pidfile if [ -d /proc/$$ ]; then # If we have /proc we can examine the process name and make # sure we don't accidentally kill something else just because # the pidfile is stale. if [ -d /proc/$pid ]; then read procname < /proc/$pid/comm case $procname in $1 | */$1 ) kill $pid ;; esac fi else kill -0 $pid 2> /dev/null && kill $pid fi fi } _osd_cat() { kill_prior osd_cat font="-*-bitstream vera sans-medium-r-*-*-24-*-*-*-*-*-*-*" osd_cat --color green \ --pos bottom \ --offset 100 \ --indent 60 \ --delay 3 \ --shadow 2 \ --lines 2 \ --font "$font" \ ${1+"$@"} > /dev/null & echo $! > $pidfile } notify() { echo "$*" > $txtfile _osd_cat $txtfile } pct() { pct=$1 shift _osd_cat --barmode percentage --percentage "$pct" --text "$*" } setup() { umask 077 uid=${UID:-`id -u`} if [ -d /run/user/$uid ]; then # linux systemd-logind 219 or later prefix=/run/user/$uid else prefix=${TMPDIR-/tmp} fi pidfile=$prefix/.osg-msg.$uid.pid txtfile=$prefix/.osg-msg.$uid.txt } main() { setup case $1 in pct | notify ) ${1+"$@"} ;; * ) notify ${1+"$@"} ;; esac } main ${1+"$@"} # eof