@@ -618,19 +618,29 @@ function timeout() {
618618
619619############################################################
620620# function: Use `touch -d` to apply all sub-dirs recursively
621- # Params: $1 a source dir
621+ # Params: $1 a source dir path
622+ # $2 optional depth
622623############################################################
623624function touchdbyfile() {
624625 if [[ ! -d "$1 " ]]; then return 1 ; fi
625626 local _dir_=${1%/ }
627+ local _lvl_=$((${2:- 0} - 1 ))
628+ local _dig_=" yes"
626629 local _old_=$( date ' +%Y-%m-%d %H:%M:%S' -r " $1 " 2> /dev/null)
627630 local _new_=' '
628631 local _sub_=' '
629632 local _ymd_=' '
630633
634+ if [[ ${_lvl_} == 0 ]] || [[ ${_lvl_} == -255 ]]; then
635+ # Do NOT echo. Should be handled by upper caller.
636+ _dig_=" no"
637+ fi
638+
631639 for f in " ${_dir_} " /* ; do
632640 if [[ -d " $f " ]]; then
633- touchdbyfile "$f "
641+ if [[ " ${_dig_} " == " yes" ]]; then
642+ touchdbyfile " $f " ${_lvl_}
643+ fi
634644 _new_=$( date ' +%Y-%m-%d %H:%M:%S' -r " $f " 2> /dev/null)
635645 if [[ " ${_new_} " > " ${_sub_} " ]]; then
636646 _sub_=${_new_}
@@ -662,22 +672,27 @@ function touchdbyfile() {
662672# Params: a file/dir, or FMT "%Y-%m-%d %H:%M"
663673# ###########################################################
664674function touchd() {
665- local _datetime_=`date +"%Y-%m-%d %H:%M"`
675+ local _awk_=" awk '{print \$ 6,\$ 7}'"
676+ local _arg_=' -l --time-style=long-iso'
677+ local _datetime_=' date +"%Y-%m-%d %H:%M"'
666678 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])?$'
667679 local _date_iso_=' '
668680 local _dir_file_=' '
681+ local _dirdepth_=-1
669682
670683 # echo "---args: $@"
671684 for p in " $@ " ; do
672- if [[ "$p " =~ ${_dt_regex_} ]]; then
673- _date_iso_="$p "
674- elif [[ -e "$p " ]]; then
685+ if [[ -e " $p " ]]; then
675686 if [[ " ${_date_iso_} " == " " ]] && [[ ! " " == " ${_dir_file_} " ]]; then
676- _date_iso_=$(date '+%Y-%m-%d %H:%M:%S' - r "$p " 2 >/dev/null)
687+ _date_iso_=` ${_datetime_} - r " $p " `
677688 fi
678689 if [[ " ${_dir_file_} " == " " ]]; then
679690 _dir_file_=" ${p%/ } "
680691 fi
692+ elif [[ " $p " =~ ${_dt_regex_} ]]; then
693+ _date_iso_=" $p "
694+ elif [[ $p =~ ([/-]* L? )([0-9]{1,3}) ]]; then
695+ _dirdepth_=${BASH_REMATCH[2]}
681696 fi
682697 done
683698
@@ -687,9 +702,14 @@ function touchd() {
687702 touch -d " ${_date_iso_} " " ${_dir_file_} " && echo OK
688703 fi
689704 elif [[ -d " ${_dir_file_} " ]]; then
690- touchdbyfile "${_dir_file_} "
705+ touchdbyfile " ${_dir_file_} " ${_dirdepth_}
691706 else
692- echo "no-op"
707+ echo " "
708+ echo " ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
709+ echo " ┃ Syntax: ┃"
710+ echo " ┃ touchd <dir> ['yyyy-mm-dd HH:MM'] [-L][<depth>] ┃"
711+ echo " ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
712+ echo " "
693713 fi
694714}
695715
0 commit comments