Skip to content

Instantly share code, notes, and snippets.

@okunokentaro
Last active May 6, 2025 22:07
Show Gist options
  • Save okunokentaro/d3cb4e5ae8a22d61cd5b7a8c3d43073a to your computer and use it in GitHub Desktop.
Save okunokentaro/d3cb4e5ae8a22d61cd5b7a8c3d43073a to your computer and use it in GitHub Desktop.
#!/bin/zsh
if [ -z "$1" ]; then
exit 1
fi
BASEDIR="."
EXTENSIONS="ts,tsx"
TSCONFIG="./tsconfig.json"
RELATIVE_TARGET=${1#./}
PATTERN=$({
npx madge "${RELATIVE_TARGET}" \
--extensions ${EXTENSIONS} \
--ts-config ${TSCONFIG} \
--basedir "${BASEDIR}" \
| sed '/^Processed/d;/^$/d'
npx madge --depends "${RELATIVE_TARGET}" \
--extensions ${EXTENSIONS} \
--ts-config ${TSCONFIG} \
--basedir "${BASEDIR}" \
"${BASEDIR}" \
| sed '/^Processed/d;/^$/d'
} | sed 's/[.[\*^$()+?{|]/\\&/g' | paste -sd'|' -)
if [ "$2" = "-l" ]; then
rg --files | rg "$PATTERN"
else
rg --files | rg "$PATTERN" | xargs rg "."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment