mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-06 13:50:15 +00:00
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.
27 lines
470 B
Bash
Executable File
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
|