Last active
March 21, 2025 15:55
-
-
Save mcanouil/f2cc41af46209975573c69a7100b7ae8 to your computer and use it in GitHub Desktop.
Search text in files from GitHub repositories
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
#!/usr/bin/env bash | |
CSV_FILE="https://raw.githubusercontent.com/mcanouil/quarto-extensions/refs/heads/main/extensions/quarto-extensions.csv" | |
KEYWORD="\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}" | |
includes_keyword() { | |
local repo=$1 | |
local branch=$2 | |
local keyword=$3 | |
if [[ "${repo}" == */*/* ]]; then | |
repo=${repo%/*} | |
fi | |
tex_files=$(gh api -X GET "repos/${repo}/git/trees/${branch}?recursive=1" --jq '.tree[] | select(.path | endswith(".tex")) | .path' 2>/dev/null) | |
if [[ "${tex_files}" == *'"status":"404"'* ]]; then | |
echo "${tex_files}" | |
return 0 | |
fi | |
while IFS= read -r file; do | |
file_content=$(gh api -X GET "repos/${repo}/contents/${file}?ref=${branch}" --jq '.content' 2>/dev/null | base64 --decode) | |
if [[ "${file_content}" == *"${keyword}"* ]]; then | |
echo "${repo}" | |
return 0 | |
fi | |
done <<< "${tex_files}" | |
return 1 | |
} | |
curl -s "${CSV_FILE}" | while IFS= read -r REPO; do | |
RESULT=$(includes_keyword "${REPO}" "main" "${KEYWORD}") | |
if [[ "${RESULT}" == *'"status":"404"'* ]]; then | |
RESULT=$(includes_keyword "${REPO}" "master" "${KEYWORD}") | |
fi | |
if [[ "${RESULT}" == *'"status":"404"'* ]]; then | |
echo "${REPO} has not main or master branch." | |
fi | |
if [[ -n "${RESULT}" && "${RESULT}" != *'"status":"404"'* ]]; then | |
echo "https://github.com/${RESULT}" | |
fi | |
done |
Author
mcanouil
commented
Mar 20, 2025
•
#!/usr/bin/env bash
CSV_FILE="https://raw.githubusercontent.com/mcanouil/quarto-extensions/refs/heads/main/extensions/quarto-extensions.csv"
has_latex() {
local repo=$1
local branch=$2
if [[ "${repo}" == */*/* ]]; then
repo=${repo%/*}
fi
files=$(gh api -X GET "repos/${repo}/git/trees/${branch}?recursive=1" --jq '.tree[] | select(.path | endswith(".tex")) | .path' 2>/dev/null)
if [[ "${files}" == *'"status":"404"'* ]]; then
return 0
fi
if [[ -n "${files}" ]]; then
echo "${repo}"
return 1
fi
return 0
}
curl -s "${CSV_FILE}" | while IFS= read -r REPO; do
RESULT=$(has_latex "${REPO}" "main")
if [[ "${RESULT}" == *'"status":"404"'* ]]; then
RESULT=$(has_latex "${REPO}" "master")
fi
if [[ "${RESULT}" == *'"status":"404"'* ]]; then
echo "${REPO} has no main or master branch."
fi
if [[ -n "${RESULT}" && "${RESULT}" != *'"status":"404"'* ]]; then
echo "https://github.com/${RESULT}"
fi
done
#!/usr/bin/env bash
CSV_FILE="https://raw.githubusercontent.com/mcanouil/quarto-extensions/refs/heads/main/extensions/quarto-extensions.csv"
SEARCH_FILE="template.qmd"
includes_file() {
local repo=$1
local branch=$2
local search_file=$3
gh api -X GET "repos/${repo}/git/trees/${branch}?recursive=1" --jq ".tree[] | select(.path | endswith(\"${search_file}\"))" 2>/dev/null
}
curl -s "${CSV_FILE}" | while IFS= read -r REPO; do
RESULT=$(includes_file "${REPO}" "main" "${SEARCH_FILE}")
if [[ "${RESULT}" == *'"status":"404"'* ]]; then
RESULT=$(includes_file "${REPO}" "master" "${SEARCH_FILE}")
fi
if [ -n "${RESULT}" ] && [[ "${RESULT}" != *'"status":"404"'* ]]; then
echo "https://github.com/${REPO}"
fi
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment