Created
June 22, 2026 06:31
-
-
Save shymonk/21ee78c7221702dffa5e656c61213d5b to your computer and use it in GitHub Desktop.
agyaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| agyaml() { | |
| local key="$1" | |
| local root="${key%%.*}" | |
| find . -type f \( -name '*.yml' -o -name '*.yaml' \) -print0 | | |
| while IFS= read -r -d '' f; do | |
| if yq -e ".$key" "$f" >/dev/null 2>&1; then | |
| echo "==> $f" | |
| awk -v root="$root" ' | |
| BEGIN { split("", ctx) } | |
| # 记录 root block(只匹配一次) | |
| $0 ~ "^[[:space:]]*"root":" && !seen[NR] { | |
| seen[NR]=1 | |
| ctx[NR]=1 | |
| for(i=NR-2;i<=NR+2;i++) ctx[i]=1 | |
| } | |
| { lines[NR]=$0 } | |
| END { | |
| for(i=1;i<=NR;i++) { | |
| if (ctx[i]) | |
| printf "%d: %s\n", i, lines[i] | |
| } | |
| } | |
| ' "$f" | |
| echo "---" | |
| echo | |
| fi | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment