Skip to content

Commit d3c4a43

Browse files
committed
added touchd function in bashrc
1 parent b7a33a7 commit d3c4a43

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tools/bashrc.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)