1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-06-29 02:17:12 -07: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

31 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