32 lines
664 B
Bash
32 lines
664 B
Bash
# run something recursively over all directories.
|
|
# usage: recursive [COMMAND]
|
|
recursive()
|
|
{
|
|
local IFS=$'\n'
|
|
local current="${PWD}"
|
|
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 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
|