recursive : return error on errors.

This commit is contained in:
Dmitry Voronin 2023-11-25 19:21:41 +03:00
parent 38731379a9
commit ba1d41d18c

View file

@ -1,5 +1,5 @@
# run something recursively over all directories. # Run something recursively over all directories.
# usage: recursive [COMMAND] # Usage: recursive <COMMAND>
recursive() recursive()
{ {
local IFS=$'\n' local IFS=$'\n'
@ -7,28 +7,31 @@ recursive()
local dirs=$(find -type d) local dirs=$(find -type d)
local total=$(find -type d | wc -l) # TODO: don't call find twice. won't work with "echo ${dirs}". local total=$(find -type d | wc -l) # TODO: don't call find twice. won't work with "echo ${dirs}".
local count=0 local count=0
local failed=0
for dir in ${dirs}; do for dir in ${dirs}; do
# increment counter. # increment counter.
((count++)) ((count++))
# cd into the next dir. # cd into the next dir.
cd "${current}" cd "${current}" || failed=${?}
cd "${dir}" cd "${dir}" || failed=${?}
# echo status. # echo status.
echo -e "${color_bblue}[${count}/${total}] ${dir}${color_default}" echo -e "${color_bblue}[${count}/${total}] ${dir}${color_default}"
# run command. # run command.
$* $* || failed=${?}
done done
# return back on complete. # return back on complete.
cd "${current}" cd "${current}" || failed=${?}
return ${failed}
} }
# run something recursively over all directories. # Run something recursively over all directories.
# usage: recursive [COMMAND] # Usage: recursive1 <COMMAND>
recursive1() # TODO: create generic function. recursive1() # TODO: create generic function.
{ {
local IFS=$'\n' local IFS=$'\n'
@ -36,6 +39,7 @@ recursive1() # TODO: create generic function.
local dirs=$(find -mindepth 1 -maxdepth 1 -type d) 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 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 local count=0
local failed=0
for dir in ${dirs}; do for dir in ${dirs}; do
# increment counter. # increment counter.
@ -49,11 +53,13 @@ recursive1() # TODO: create generic function.
echo -e "${color_bblue}[${count}/${total}] ${dir}${color_default}" echo -e "${color_bblue}[${count}/${total}] ${dir}${color_default}"
# run command. # run command.
$* $* || failed=${?}
done done
# return back on complete. # return back on complete.
cd "${current}" cd "${current}"
return ${failed}
} }
# autocomplete. # autocomplete.