1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-05-18 09:53:22 -07:00

add dated util to handle epoch timestamps

because i'm lazy
This commit is contained in:
Connor Olding 2021-10-18 02:47:32 -07:00
parent ffd8b9ec9c
commit e5c8fea542

21
sh/dated Normal file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env sh
# YES_ZSH
# YES_BASH
# YES_DASH
# YES_ASH
dated() {
local u=0
[ "$1" != -u ] || { shift; u=1; }
argc $# -le 1 "$0" || return
if [ $# = 0 ]; then
# -u doesn't actually do anything here, but...
if [ $u = 1 ]; then date -u '+%s'; else date '+%s'; fi
else
if [ $u = 1 ]; then date -u -d '@'"$1"; else date -d '@'"$1"; fi
fi
}
[ -n "${preload+-}" ] || . ~/sh/preload || exit 2
eval ${preload:-preload} argc
[ -n "${preload+-}" ] || dated "$@"