bin/since: refactor
This commit is contained in:
parent
ae737424b8
commit
2cdc8e460a
10
bin/since
10
bin/since
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
(( $# > 0 )) || return
|
(( $# > 0 )) || exit
|
||||||
|
|
||||||
# Displays the time since $1 in a human readable format (e.g. 4h 25m 55s). If given a
|
# Displays the time since $1 in a human readable format (e.g. 4h 25m 55s). If given a
|
||||||
# file, the modified time is used. If $1 == "--", then this script acts as a converter,
|
# file, the modified time is used. If $1 == "--", then this script acts as a converter,
|
||||||
|
@ -11,18 +11,18 @@ set -e
|
||||||
|
|
||||||
# `date` on OSX does not have the --date parameter
|
# `date` on OSX does not have the --date parameter
|
||||||
date=date
|
date=date
|
||||||
if [[ "$OSTYPE" == darwin* ]]; then
|
if [[ $OSTYPE == darwin* ]]; then
|
||||||
date=gdate
|
date=gdate
|
||||||
else
|
elif ! command -v $date >/dev/null; then
|
||||||
echo "Unsupported system"
|
echo "Unsupported system"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If given a file, give time since last modification
|
# If given a file, give time since last modification
|
||||||
(( $# == 1 )) && [[ -f "$*" ]] && arg=reference || arg=date
|
(( $# == 1 )) && [[ -f $@ ]] && arg=reference || arg=date
|
||||||
|
|
||||||
args="$*"
|
args="$*"
|
||||||
if [[ "$1" == "--" ]]; then
|
if [[ $1 == -- ]]; then
|
||||||
t="$2"
|
t="$2"
|
||||||
else
|
else
|
||||||
now=$(${date} +%s)
|
now=$(${date} +%s)
|
||||||
|
|
Loading…
Reference in a new issue