Files
dotfiles/local/bin/x-foreach
Ismo Vuorinen efd9eebc85 fix: resolve critical issues in x-clean-vendordirs, x-foreach, x-ip
x-clean-vendordirs: remove broken msgr dependency (not sourced),
add set -euo pipefail. x-foreach: replace eval on command args with
direct "$@" execution, add usage guard. x-ip: add set -euo pipefail,
curl dependency check, and silent-fail flag.
2026-02-05 22:07:03 +02:00

27 lines
470 B
Bash
Executable File

#!/usr/bin/env bash
#
# Run a command in each directory matching a pattern.
#
# Usage: x-foreach <listing-command> <command> [args...]
# x-foreach "ls -d */" "git status"
#
# Source: https://github.com/mvdan/dotfiles/blob/master/.bin/foreach
set -euo pipefail
if [ $# -lt 2 ]; then
echo "Usage: $0 <listing-command> <command> [args...]"
exit 1
fi
listing=$1
shift
for dir in $(eval "$listing"); do
(
echo "$dir"
cd "$dir" || exit 1
"$@"
)
done