Skip to content

Instantly share code, notes, and snippets.

@vbrozik
Last active June 29, 2023 15:45
Show Gist options
  • Save vbrozik/ebec7b5f5f9ae6a5306a1869f9d6443a to your computer and use it in GitHub Desktop.
Save vbrozik/ebec7b5f5f9ae6a5306a1869f9d6443a to your computer and use it in GitHub Desktop.
GitHub CLI

GitHub CLI (gh)

Useful scripts

# list all my repositories
gh repo list --json nameWithOwner --jq '.[].nameWithOwner'

# gh api

headers=(
    -H "Accept: application/vnd.github+json"
    -H "X-GitHub-Api-Version: 2022-11-28"
)
name_with_owner=vbrozik/asa-cp-conv

# list all files in a repository
gh api "${headers[@]}" "/repos/${name_with_owner}/git/trees/main?recursive=true" --jq '.tree[].path'

# list all files in all repositories
for name_with_owner in $(gh repo list --json nameWithOwner --jq '.[].nameWithOwner') ; do
    printf '### %s\n' "$name_with_owner"
    gh api "${headers[@]}" "/repos/${name_with_owner}/git/trees/main?recursive=true" --jq '.tree[].path'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment