1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 02:39:03 -08:00
rc/sh/minutemaid
Connor Olding d35c492850 NixOS compatibility
* use /usr/bin/env for all hashbangs
* enable hashall for bash
* workaround syntax error in -shrc for bash
2020-12-29 18:04:04 +01:00

30 lines
676 B
Bash
Executable file

#!/usr/bin/env zsh
# crontab usage:
#* * * * * minutemaid 9 cd repo && git pull # runs every nine minutes
local offset=0 opt=
while getopts 'o:h' opt; do
case $opt in
o) offset="$OPTARG";;
?) local fd=0
[ $opt = h ] && fd=0 || fd=2
echo -E "usage: $0 [-o offset] {interval} [{command} [{args...}]]" >&$fd
[ $opt = h ] && return 0 || return 1;;
esac
done
shift $((OPTIND-1))
local interval="${1:?no interval specified}"
shift
local sec="$(date +%s)"
let min=sec/60+offset
let mod=min%interval
if [ $# -gt 0 ]; then
local cmd="${1}"
shift
[ $mod -eq 0 ] && "$cmd" "$@"
else
[ $mod -eq 0 ] && return 0 || return 1
fi