dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles # fast
git clone https://src.adamsgaard.dk/dotfiles.git # slow
Log | Files | Refs | README | LICENSE Back to index

commit 4de19e8029d52b9095e5c77c80ab03f5e84631cd
parent 01917c7e1d5da7546ce09e6466e36a1d7b3c1cab
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed,  3 Feb 2021 12:44:05 +0100

watch.sh: remove unnecessary code

Diffstat:
M.local/bin/watch.sh | 76+++++++++++++++++++++++++++-------------------------------------------------
1 file changed, 27 insertions(+), 49 deletions(-)

diff --git a/.local/bin/watch.sh b/.local/bin/watch.sh @@ -1,69 +1,47 @@ #!/bin/sh -version=1.0.1 -waitsecs=5 - -show_help() { - echo "usage: ${0##*/} [OPTIONS] COMMAND" - echo "will repeatedly run COMMAND every $waitsecs seconds." - echo - echo "OPTIONS are one or more of the following:" - echo " -h, --help show this message" - echo " -v, --version show version and license information" - echo " -n, --interval SECONDS interval between command invocations" - echo " -- do not consider any following args as options" -} - -show_version() { - echo "${0##*/} version $version" - echo "Licensed under the ISC License" - echo "written by Anders Damsgaard, anders@adamsgaard.dk" - echo "https://src.adamsgaard.dk/dotfiles" -} - die() { - printf '%s\n' "$1" >&2 + printf '%s: error: %s\n' "${0%%*/}" "$1" >&2 exit 1 } -[ -f ~/.profile ] && . ~/.profile +usage() { + die "usage: ${0##*/} [-h] [-n SECONDS] COMMAND" +} +wait=5 while :; do case "$1" in - -h|-\?|--help) - show_help - exit 0 - ;; - -v|--version) - show_version - exit 0 - ;; - -n|--interval) - waitsecs="$2" - shift - ;; + -h) + usage;; + -n) + wait="$2" + shift;; --) # end all options shift - break - ;; + break;; -?*) - die 'Error: Unknown option specified' - ;; - *) # No more options - break + die 'unknown option specified' + break;; + *) + break;; esac shift done -if [ $# -lt 1 ]; then - show_help - exit 1 +if test $# -lt 1; then + usage fi -while : ; do +if test -f ~/.profile; then + . ~/.profile +fi + +host="${USER}@$(hostname):${PWD}" +while :; do clear - printf "%s" "Every ${waitsecs}s: $*" - printf "\t %s\n" "$(hostname): $(date)" - "$@" - sleep "$waitsecs" + printf '%s (%ds) %s: %s\n' \ + "$(date '+%F %T')" "${wait}" "${host}" "$*" + eval "$@" + sleep "${wait}" done