Skip to content

Commit c50f131

Browse files
committed
updated touchd function in bashrc.sh
1 parent e232247 commit c50f131

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

tools/bashrc.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,23 @@ function touchdbyfile() {
667667
fi
668668
}
669669

670+
############################################################
671+
# function: Use `touch -d` to apply all basepath recursively
672+
# Params: $1 a source dir paths
673+
############################################################
674+
function touchdpath {
675+
if [[ ! -d "$1" ]]; then return 1; fi
676+
local _spath_="$( cd "$( echo "${1}" )" && pwd )"
677+
local _sbase_="$( cd "${_spath_}/.." && pwd )"
678+
local _slash_=${_spath_//[!\/]}
679+
local _depth_=${#_slash_}
680+
681+
if [[ ${_depth_} -gt 2 ]]; then
682+
touchdbyfile "${_spath_}" 1
683+
touchdpath "${_sbase_}"
684+
fi
685+
}
686+
670687
############################################################
671688
# function: Use `touch -d` on file/dir
672689
# Params: a file/dir, or FMT "%Y-%m-%d %H:%M"
@@ -702,7 +719,11 @@ function touchd() {
702719
touch -d "${_date_iso_}" "${_dir_file_}" && echo OK
703720
fi
704721
elif [[ -d "${_dir_file_}" ]]; then
705-
touchdbyfile "${_dir_file_}" ${_dirdepth_}
722+
if [[ ${_dirdepth_} -ne 0 ]]; then
723+
touchdbyfile "${_dir_file_}" ${_dirdepth_}
724+
else
725+
touchdpath "${_dir_file_}"
726+
fi
706727
else
707728
echo ""
708729
echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"

0 commit comments

Comments
 (0)