-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
#!/usr/bin/env bash | ||
usage() { echo -e "Make copy of file with last change date at end.\nUSAGE: $0 myfile # makes myfile.YYYY-MM-DD"; } | ||
[[ $# -eq 0 || $* =~ ^-+h ]] && usage && exit 1 | ||
|
||
# move if first arg is --mv | ||
cp=cp | ||
[[ "$1" == '--mv' ]] && cp=mv && shift 1 | ||
|
||
while [ $# -gt 0 ]; do | ||
infile="${1:?file to copy}"; shift | ||
[ ! -r "$infile" ] && warn "Bad file: '$infile'" && continue | ||
infile="${1:?file to copy}"; shift | ||
[ ! -r "$infile" ] && warn "Bad file: '$infile'" && continue | ||
[[ ${infile} =~ /$ ]] && infile=${infile::-1} | ||
|
||
newname=$infile.$(find "$infile" -printf '%CF') | ||
[ -r "$newname" ] && warn "$newname aleady exists!. remove and rerun to replace" && continue | ||
newname=$infile.$(find "$infile" -maxdepth 0 -printf '%CF') | ||
[ -r "$newname" ] && warn "$newname aleady exists!. remove and rerun to replace" && continue | ||
|
||
dryrun cp "$infile" "$newname" | ||
dryrun $cp "$infile" "$newname" | ||
done |