2023-11-25 19:21:41 +03:00
|
|
|
# Run something recursively over all directories.
|
|
|
|
# Usage: recursive <COMMAND>
|
2023-10-29 20:09:39 +03:00
|
|
|
recursive()
|
|
|
|
{
|
2023-10-29 21:26:22 +03:00
|
|
|
local IFS=$'\n'
|
2023-10-29 20:09:39 +03:00
|
|
|
local current="${PWD}"
|
|
|
|
local dirs=$(find -type d)
|
2023-10-29 21:26:22 +03:00
|
|
|
local total=$(find -type d | wc -l) # TODO: don't call find twice. won't work with "echo ${dirs}".
|
2023-10-29 20:09:39 +03:00
|
|
|
local count=0
|
2023-11-25 19:21:41 +03:00
|
|
|
local failed=0
|
2023-10-29 20:09:39 +03:00
|
|
|
|
|
|
|
for dir in ${dirs}; do
|
|
|
|
# increment counter.
|
|
|
|
((count++))
|
|
|
|
|
|
|
|
# cd into the next dir.
|
2023-11-25 19:21:41 +03:00
|
|
|
cd "${current}" || failed=${?}
|
|
|
|
cd "${dir}" || failed=${?}
|
2023-10-29 20:09:39 +03:00
|
|
|
|
|
|
|
# echo status.
|
2023-11-18 11:17:53 +03:00
|
|
|
echo -e "${color_bblue}[${count}/${total}] ${dir}${color_default}"
|
2023-10-29 20:09:39 +03:00
|
|
|
|
|
|
|
# run command.
|
2023-11-25 19:21:41 +03:00
|
|
|
$* || failed=${?}
|
2023-10-29 20:09:39 +03:00
|
|
|
done
|
|
|
|
|
|
|
|
# return back on complete.
|
2023-11-25 19:21:41 +03:00
|
|
|
cd "${current}" || failed=${?}
|
|
|
|
|
|
|
|
return ${failed}
|
2023-10-29 20:09:39 +03:00
|
|
|
}
|
|
|
|
|
2023-11-25 19:21:41 +03:00
|
|
|
# Run something recursively over all directories.
|
|
|
|
# Usage: recursive1 <COMMAND>
|
2023-11-18 11:09:47 +03:00
|
|
|
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
|
2023-11-25 19:21:41 +03:00
|
|
|
local failed=0
|
2023-11-18 11:09:47 +03:00
|
|
|
|
|
|
|
for dir in ${dirs}; do
|
|
|
|
# increment counter.
|
|
|
|
((count++))
|
|
|
|
|
|
|
|
# cd into the next dir.
|
|
|
|
cd "${current}"
|
|
|
|
cd "${dir}"
|
|
|
|
|
|
|
|
# echo status.
|
2023-11-18 11:17:53 +03:00
|
|
|
echo -e "${color_bblue}[${count}/${total}] ${dir}${color_default}"
|
2023-11-18 11:09:47 +03:00
|
|
|
|
|
|
|
# run command.
|
2023-11-25 19:21:41 +03:00
|
|
|
$* || failed=${?}
|
2023-11-18 11:09:47 +03:00
|
|
|
done
|
|
|
|
|
|
|
|
# return back on complete.
|
|
|
|
cd "${current}"
|
2023-11-25 19:21:41 +03:00
|
|
|
|
|
|
|
return ${failed}
|
2023-11-18 11:09:47 +03:00
|
|
|
}
|
|
|
|
|
2023-10-29 20:09:39 +03:00
|
|
|
# autocomplete.
|
2023-11-18 11:09:47 +03:00
|
|
|
complete -F _autocomplete_nested recursive recursive1
|