Skip to content

Instantly share code, notes, and snippets.

@shymonk
Created June 22, 2026 06:31
Show Gist options
  • Select an option

  • Save shymonk/21ee78c7221702dffa5e656c61213d5b to your computer and use it in GitHub Desktop.

Select an option

Save shymonk/21ee78c7221702dffa5e656c61213d5b to your computer and use it in GitHub Desktop.
agyaml
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