File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -615,6 +615,43 @@ function timeout() {
615615 fi
616616}
617617
618+ ############################################################
619+ # function: Use `touch -d` on file/dir
620+ # Params: a file/dir, or FMT "%Y-%m-%d %H:%M"
621+ ############################################################
622+ function touchd() {
623+ local _awk_="awk '{print \$6 ,\$7 }'"
624+ local _arg_='-l --time-style=long-iso'
625+ local _datetime_=`date +"%Y-%m-%d %H:%M"`
626+ local _dt_regex_='^[0 -9 ][0 -9 ][0 -9 ][0 -9 ]-[0 -9 ][0 -9 ]-[0 -9 ][0 -9 ]( [0 -9 ][0 -9 ]:[0 -9 ][0 -9 ])?$'
627+ local _date_iso_=''
628+ local _dir_file_=''
629+
630+ # echo "---args: $@ "
631+ for p in "$@ "; do
632+ if [[ "$p " =~ ${_dt_regex_} ]]; then
633+ _date_iso_="$p "
634+ elif [[ -d "$p " ]]; then
635+ if [[ "${_date_iso_} " == "" ]]; then
636+ IFS=$'\n'
637+ for a in `ls -l --time-style=long-iso "$p "|awk '{print $6 ,$7 }'`; do
638+ _date_iso_="$a "
639+ done
640+ fi
641+ _dir_file_="$p "
642+ fi
643+ done
644+
645+ if [[ "${_date_iso_} " =~ ${_dt_regex_} ]]; then
646+ if [[ -e "${_dir_file_} " ]]; then
647+ echo "Applying '${_date_iso_} ' on ${_dir_file_} "
648+ touch -d "${_date_iso_} " "${_dir_file_} " && echo OK
649+ fi
650+ else
651+ echo "no-op"
652+ fi
653+ }
654+
618655############################################################
619656# function: Use youtube-dl or yt-dlp
620657# see
You can’t perform that action at this time.
0 commit comments