Skip to content

Commit

Permalink
cp-date: add move option
Browse files Browse the repository at this point in the history
  • Loading branch information
WillForan committed Nov 22, 2024
1 parent b2ab5a8 commit cc70ade
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cp-date
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

0 comments on commit cc70ade

Please sign in to comment.