Skip to content

Commit bd66838

Browse files
committed
updated touchd and ydlo functions in bashrc.sh
1 parent 1763559 commit bd66838

1 file changed

Lines changed: 45 additions & 12 deletions

File tree

tools/bashrc.sh

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ alias cdp='cd -P .'
5050
alias clean='find . -type f \( -name *.DS_Store -o -name Thumbs.db \) -delete 2>/dev/null'
5151
alias cls='clear && printf "\e[3J"'
5252
alias conv='iconv -f windows-1252 -t utf-8'
53+
alias convgbk='iconv -f gbk -t utf-8'
5354
alias dater='date +"%Y-%m-%d %H:%M:%S" -r'
5455
alias dated='date +"%Y-%m-%d %H:%M:%S" -d'
5556
alias dh='du -hs'
@@ -64,6 +65,7 @@ alias fixgrayedout='xattr -d com.apple.FinderInfo'
6465
alias fixmod='for f in *; do if [[ -d "$f" ]] || [[ "${f##*.}" == "sh" ]]; then chmod 755 "$f"; else chmod 644 "$f"; fi; done'
6566
alias fixrar='/Applications/rar/rar r'
6667
alias fixunzip='ditto -V -x -k --sequesterRsrc ' # $1.zip $2/dir'
68+
alias hide='chflags hidden'
6769
alias hs='history | grep'
6870
alias ip='echo $(ipconfig getifaddr en0) $(dig +short myip.opendns.com @resolver1.opendns.com)'
6971
alias ll='ls -al'
@@ -84,11 +86,13 @@ alias rarx='unrar x -kb'
8486
alias setp='(set -o posix; set|grep -v _xspec)'
8587
alias showhidden='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app'
8688
alias si='echo -e $(for k in ~/.ssh/*.pub;do echo -e "\\\n$(ssh-keygen -E md5 -lf $k) - $k";done)|sort -k 3; echo;echo "--- Added identities ---"; ssh-add -E md5 -l|sort -k 3'
89+
alias sshv='ssh -v -o HostKeyAlgorithms=ssh-dss -o KexAlgorithms=diffie-hellman-group14-sha1'
8790
alias ver='echo -e "$(uname -a)"; echo ""; echo -e "$(bash --version)"'
8891
alias vlc='/Applications/VLC.app/Contents/MacOS/VLC --width 800 --height 600 --aspect-ratio 16x9 &'
8992
alias ydl='youtube-dl -f bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4' # -o '%(playlist_index)s.%(ext)s'
9093
alias t='title ${PWD##*/}'
9194

95+
9296
# docker-machine
9397
export DOCKER_EMAIL=''
9498
export DOCKER_USERNAME=''
@@ -631,6 +635,14 @@ function touchdbyfile() {
631635
local _opt_=${3%/}
632636
local _dig_="yes"
633637
local _old_=$(date '+%Y-%m-%d %H:%M:%S' -r "$1" 2>/dev/null)
638+
local _now_=$(date '+%Y-%m-%d %H:%M:%S')
639+
local _old_sec_=`date --date="${_old_}" +%s`
640+
local _now_sec_=`date --date="${_now_}" +%s`
641+
local _sec_=$((${_now_sec_} - ${_old_sec_}))
642+
local _num_=${_neardays_:-60}
643+
local _ddf_=$((${_sec_#-}/86400 - ${_num_}))
644+
local _dth_=$((${_lvl_} - ${_dirdepth_}))
645+
local _act_=""
634646
local _cur_=''
635647
local _sub_=''
636648
local _new_=''
@@ -640,6 +652,20 @@ function touchdbyfile() {
640652
# Do NOT echo. Should be handled by upper caller.
641653
_dig_="no"
642654
fi
655+
if [[ "${_dth_#-}" -gt 1 ]]; then
656+
if [[ ${_act_mode_} =~ --quick ]]; then
657+
if [[ ${_ddf_} -gt 0 ]]; then
658+
if [[ "${_day_skip_}" == "" ]]; then
659+
echo ""
660+
fi
661+
_day_skip_="${_ddf_}"
662+
echo "Skipping ${_old_} beyond ${_num_} days on ${_dir_}"
663+
return ${_ddf_}
664+
elif [[ ! "${_day_skip_}" == "" ]]; then
665+
_day_skip_=""
666+
fi
667+
fi
668+
fi
643669

644670
for f in "${_dir_}"/*; do
645671
if [[ -d "$f" ]]; then
@@ -678,21 +704,20 @@ function touchdbyfile() {
678704
# echo "_cur_=${_cur_} ,_sub_=${_sub_}"
679705
# echo "_opt_=${_opt_}"
680706

681-
local _act_=""
682707
if [[ "${_ymd_}" == "${_old_}" ]]; then
683708
_act_="Matching ${_ymd_} on ${_dir_}"
684709
fi
685710
if [[ "${_ymd_}" > "${_old_}" ]] && \
686711
[[ "${_opt_}" == "" ]]; then
687712
_act_="Reserved ${_old_} on ${_dir_}"
688713
fi
714+
echo ""
689715
if [[ "${_act_}" == "" ]]; then
690716
echo Applying ${_ymd_} to ${_dir_} [${_old_}]
691717
touch -d "${_ymd_}" "${_dir_}"
692718
else
693719
echo ${_act_}
694720
fi
695-
echo ""
696721
}
697722

698723
############################################################
@@ -722,15 +747,18 @@ function touchd() {
722747
local _awk_="awk '{print \$6,\$7}'"
723748
local _arg_='-l --time-style=long-iso'
724749
local _asc_sort_=''
750+
local _act_mode_='--quick'
751+
local _neardays_=${NEARDAYS:-60}
752+
local _day_skip_=''
725753
local _fmt_date_='%Y-%m-%d %H:%M'
726754
local _fmt_regx_='[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9])?'
727755
local _iso_date_=''
728756
local _dir_from_=''
729757
local _dir_file_=''
730758
local _dir_path_=''
759+
local _dirdepth_=${DIRDEPTH:-3}
731760
local _grp_dirs_=()
732761
local _grp_file_=()
733-
local _dirdepth_=-1
734762

735763
# echo "---args: $@"
736764
for p in "$@"; do
@@ -753,14 +781,16 @@ function touchd() {
753781
# [[ "${_iso_date_}" == "" ]]; then
754782
# _iso_date_="${BASH_REMATCH[1]} 00:00"
755783
# fi
756-
elif [[ $p =~ ([/-]*L?)([0-9]{1,3}) ]]; then
784+
elif [[ "$p" =~ ([/-]{1,2}L?)([0-9]{1,3}) ]]; then
757785
_dirdepth_=${BASH_REMATCH[2]}
786+
elif [[ "$p" =~ ([/-]{1,2}N)([1-9][0-9]{0,3}) ]]; then
787+
_neardays_=${BASH_REMATCH[2]}
758788
elif [[ "$p" =~ [/-]{1,2}[vV] ]]; then
759789
_asc_sort_='--asc-sort'
760790
elif [[ "$p" =~ [/-]{1,2}[fF] ]]; then
761-
if [[ "${_asc_sort_}" == "" ]]; then
762-
_asc_sort_='--always'
763-
fi
791+
_act_mode_='--always'
792+
elif [[ "$p" =~ [/-]{1,2}[kK] ]]; then
793+
_act_mode_='--quick'
764794
fi
765795
done
766796

@@ -794,8 +824,10 @@ function touchd() {
794824
echo " Sorting by oldest "
795825
echo "+-----------------+"
796826
fi
797-
echo "Recuring on ${#_grp_dirs_[@]} dir(s)..."
798-
echo ""
827+
if [[ ${_act_mode_} =~ --quick ]]; then
828+
_act_mode_="${_act_mode_} near ${_neardays_} days, depth: ${_dirdepth_}"
829+
fi
830+
echo "Recuring on ${#_grp_dirs_[@]} dir(s) ... ${_act_mode_}"
799831
for _dir_ in "${_grp_dirs_[@]}"; do
800832
local _dir_base_="$( cd "${_dir_}/.." && pwd )"
801833
if [[ ${_dirdepth_} -ne 0 ]]; then
@@ -815,6 +847,7 @@ function touchd() {
815847
echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
816848
echo ""
817849
fi
850+
echo ""
818851
}
819852

820853
############################################################
@@ -904,14 +937,14 @@ function ydlo() {
904937
fi
905938
fi
906939
if [[ ! "${_snum_}" == "" ]]; then
907-
_sarg_="--autonumber-start ${_snum_}"
940+
_sarg_="--autonumber-start ${_snum_} ${_sarg_}"
908941
_sarg_="--playlist-start ${_snum_} ${_sarg_}"
909942
if [[ ! "${_enum_}" == "" ]]; then
910943
local _xend_=$((${_enum_} - ${_snum_} + 1))
911-
_sarg_="--autonumber-start ${_snum_}"
944+
_sarg_="--autonumber-start ${_snum_} ${_sarg_}"
912945
_sarg_="--autonumber-size ${_xend_} ${_sarg_}"
913946
_sarg_="--playlist-end ${_xend_} ${_sarg_}"
914-
_sarg_="--playlist-start 1 ${_sarg_}"
947+
_sarg_="--playlist-start ${_snum_} ${_sarg_}"
915948
fi
916949
echo "start: ${_snum_}"
917950
fi

0 commit comments

Comments
 (0)