This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.config/bash/module/recursive.sh

61 lines
1.3 KiB
Bash
Raw Normal View History

2023-10-29 20:09:39 +03:00
# run something recursively over all directories.
# usage: recursive [COMMAND]
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
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}] ${dir}${color_default}"
2023-10-29 20:09:39 +03:00
# run command.
$*
done
# return back on complete.
cd "${current}"
}
2023-11-18 11:09:47 +03:00
# 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}] ${dir}${color_default}"
2023-11-18 11:09:47 +03:00
# run command.
$*
done
# return back on complete.
cd "${current}"
}
2023-10-29 20:09:39 +03:00
# autocomplete.
2023-11-18 11:09:47 +03:00
complete -F _autocomplete_nested recursive recursive1