-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatewrap.sh
executable file
·48 lines (42 loc) · 1017 Bytes
/
datewrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
#
# datewrap.sh
# now, today, yesterday, tomorrow, lastweek, nextweek, lastmonth, thisweek,
# thismonth, thisyear
#
# desc:
# convenience date wrappers
#
# scott@smemsh.net
# https://github.com/smemsh/utilsh/
# https://spdx.org/licenses/GPL-2.0
#
##############################################################################
invname=${0##*/}
yflags=%Y
mflags=%Y%m
dflags=%Y%m%d
wflags=%G%V
nflags=%Y%m%d%H%M%S
_thisweek () { date +$wflags; }
_thismonth () { date +$mflags; }
_thisyear () { date +$yflags; }
_today () { date +$dflags; }
_now () { date +$nflags; }
_nextweek () { date -d next-week +$wflags; }
_lastweek () { date -d last-week +$wflags; }
_lastmonth () { date -d last-month +$mflags; }
_yesterday () { date -d yesterday +$dflags; }
_tomorrow () { date -d tomorrow +$dflags; }
main ()
{
if [[ $(declare -F _$invname) ]]; then
_$invname "$@"
else
echo usage:
for f in $(compgen -A function _); do
echo -e \\t${f#_}; done
exit 1
fi
}
main "$@"