lishwist/scripts/upfind
2026-02-20 23:49:42 +09:00

31 lines
468 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [[ $# -eq 0 ]]; then
echo "Usage: upfind <glob> [glob...]" >&2
exit 1
fi
dir="$(pwd)"
dirs=()
while true; do
dirs+=("$dir")
parent="$(dirname "$dir")"
if [[ "$parent" == "$dir" ]]; then
break
fi
dir="$parent"
done
for (( i=${#dirs[@]}-1; i>=0; i-- )); do
for glob in "$@"; do
for match in "${dirs[$i]}"/$glob; do
if [[ -e "$match" ]]; then
echo "$match"
fi
done
done
done