0

Is there an existing tool which will do something like this:

git-cat https://github.com/AbhishekSinhaCoder/Collection-of-Useful-Scripts

then it will run cat on each file in the repo?

Something like this works but it doesn't separate the files:

curl -s -H "Accept:application/vnd.github.v3.raw" https://api.github.com/repos/AbhishekSinhaCoder/Collection-of-Useful-Scripts/contents/ | 
jq .[].download_url -r | 
xargs curl 2>/dev/null | 
bat
jaksco
  • 156
  • here is one way :/ https://unix.stackexchange.com/a/421570/426217 – jaksco Nov 01 '20 at 08:02
  • If you run cat on each file, then they'll all be concatenated. However, your answer indicates that you don't want that. What behavior do you want? – bk2204 Nov 12 '20 at 02:40
  • The best behavior would be per file with language recognition in bat and when I quit out of the bat pager then it will show the next file – jaksco Nov 13 '20 at 03:07

1 Answers1

2

This is possible with a small modification to your command line:

curl -s -H "Accept:application/vnd.github.v3.raw" https://api.github.com/repos/AbhishekSinhaCoder/Collection-of-Useful-Scripts/contents/ | 
jq .[].download_url -r | 
xargs -L1 sh -c 'curl "$0" 2>/dev/null | bat'

Having said that, if there are a large number of files, you may end up getting rate-limited due to making too many requests, or your results may end up incomplete because they're paginated. You may wish to do a shallow clone (git clone --depth=1) or a partial clone (git clone --filter=blob:none) if you'd rather not have the expense of a full clone.

bk2204
  • 4,099
  • 7
  • 9
  • yeah this works pretty well! Note that you can use bat --paging=always to prevent small files from printing directly into the shell – jaksco Nov 14 '20 at 18:12