2021-07-29 00:37:35 -07:00
|
|
|
#!/usr/bin/env sh
|
2024-07-22 05:28:58 -07:00
|
|
|
# compat: +ash +bash +dash +zsh
|
2021-07-29 00:37:35 -07:00
|
|
|
|
2021-08-23 04:52:23 -07:00
|
|
|
baknow() { ### @- backup files by appending their timestamps given by [`now`.](#now)
|
2021-08-01 07:58:21 -07:00
|
|
|
### ```
|
|
|
|
### $ touch -d '2001-12-25 16:30:00' butts
|
|
|
|
### $ baknow butts
|
|
|
|
### $ baknow butts
|
|
|
|
### cp: overwrite 'butts.2001-12-26_01800000.bak'? n
|
|
|
|
### $ ls -l
|
|
|
|
### total 0
|
|
|
|
### -rw-r--r-- 1 notwa None 0 Dec 25 2001 butts
|
|
|
|
### -rw-r--r-- 1 notwa None 0 Dec 25 2001 butts.2001-12-26_01800000.bak
|
|
|
|
### ```
|
2021-10-13 23:02:51 -07:00
|
|
|
argc $# -ge 1 "$0" || return
|
2022-03-06 13:12:17 -08:00
|
|
|
local ret=0 f=
|
2021-08-23 04:52:23 -07:00
|
|
|
for f; do
|
|
|
|
cp -ip "$f" "$f.$(now "$f").bak" || ret=1
|
|
|
|
done
|
|
|
|
return $ret
|
2021-07-29 00:37:35 -07:00
|
|
|
}
|
|
|
|
|
2021-08-23 04:52:23 -07:00
|
|
|
[ -n "${preload+-}" ] || . ~/sh/preload || exit 2
|
|
|
|
eval ${preload:-preload} argc now
|
2021-08-02 13:48:46 -07:00
|
|
|
[ -n "${preload+-}" ] || baknow "$@"
|