1
0
Fork 0

bin: now / timestamp

This commit is contained in:
Jeremy Kaplan 2026-04-11 23:26:38 -04:00
commit d82fe28a77
2 changed files with 30 additions and 8 deletions

28
bin/now Executable file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
style="${1:-iso}"
flags=()
if [[ "${style}" =~ -utc ]]; then
style="${style%-utc}"
flags+=('--utc')
fi
format=''
case "${style}" in
iso) format='--iso-8601=seconds' ;;
date) format='+%Y-%m-%d' ;;
human) format='+%Y-%m-%d %H:%M %z' ;;
unix) format='+%s' ;;
js) format='+%s%3N' ;;
fs) format='+%Y%m%d_%H%M%S' ;;
zone) format='+%z' ;;
*)
>&2 echo "Unknown format: ${style}"
exit 1
;;
esac
exec date "${flags[@]}" "${format}"