From 71333b66d9f0f5d1c77b292c2f5bde86b718ec10 Mon Sep 17 00:00:00 2001 From: phone Date: Sat, 18 Nov 2023 11:09:47 +0300 Subject: [PATCH] recursive1 : exec in depth 1. --- .README.md | 1 + .config/bash/module/recursive.sh | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.README.md b/.README.md index 5e3059f..c98efa9 100644 --- a/.README.md +++ b/.README.md @@ -586,6 +586,7 @@ Command|Description Command|Description ---|--- `recursive `|Cd into every directory recursively and run specified command in each dir. +`recursive1 `|Cd into every directory in current directory and run specified command in each dir. ## Shopt. diff --git a/.config/bash/module/recursive.sh b/.config/bash/module/recursive.sh index 90e4f82..2b3811b 100644 --- a/.config/bash/module/recursive.sh +++ b/.config/bash/module/recursive.sh @@ -27,5 +27,34 @@ recursive() cd "${current}" } +# run something recursively over all directories. +# usage: recursive [COMMAND] +recursive1() # TODO: create generic function. +{ + local IFS=$'\n' + local current="${PWD}" + local dirs=$(find -mindepth 1 -maxdepth 1 -type d) + local total=$(find -mindepth 1 -maxdepth 1 -type d | wc -l) # TODO: don't call find twice. won't work with "echo ${dirs}". + local count=0 + + for dir in ${dirs}; do + # increment counter. + ((count++)) + + # cd into the next dir. + cd "${current}" + cd "${dir}" + + # echo status. + echo -e "${color_bblue}[${count}/${total}] recursive dir: ${dir}${color_default}" + + # run command. + $* + done + + # return back on complete. + cd "${current}" +} + # autocomplete. -complete -F _autocomplete_nested recursive +complete -F _autocomplete_nested recursive recursive1