bash : add recursive function.

This commit is contained in:
Dmitry Voronin 2023-10-29 20:09:39 +03:00
parent 3e59bca232
commit 904edf910d
2 changed files with 35 additions and 0 deletions

View file

@ -538,6 +538,11 @@ Command|Description
---|---
`ps [PROGRAM]`|Show process info for matching [PROGRAM] name.
## Recursive.
Command|Description
---|---
`recursive [COMMAND]`|Cd into every directory recursively and run specified command in each dir.
## Shopt.
Shopt|Description

View file

@ -0,0 +1,30 @@
# run something recursively over all directories.
# usage: recursive [COMMAND]
recursive()
{
local current="${PWD}"
local dirs=$(find -type d)
local total=$(echo ${dirs} | wc -w)
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_blue}[${count}/${total}] recursive dir: ${dir}${color_default}"
# run command.
$*
done
# return back on complete.
cd "${current}"
}
# autocomplete.
complete -F _autocomplete_nested recursive