curl \
-H "Accept: application/vnd.github.v3+json" \
-s https://api.github.com/repos/torvalds/linux | \
jq '.size' | \
numfmt --to=iec --from-unit=1024
Explanation:
- fetch repo info from github api using curl
We get a json response like this:
{
"id": 2325298,
"node_id": "MDEwOlJlcG9zaXRvcnkyMzI1Mjk4",
"name": "linux",
"full_name": "torvalds/linux",
"private": false,
...
"size": 3018913, <<<This is what we need
"stargazers_count": 99224,
"watchers_count": 99224,
...
}
Pipe the json response to jq parser and find the required attribute-value pair.
.
indicates the root of the json body and size
is the required attribute from the root body
Output (the size in kB):
3018913
- Then pipe the output to numfmt
$ man numfmt
--to=[UNIT]
iec 1K = 1024, 1M = 1048576, ...
--from-unit=N
specify the input unit size (instead of the default 1)
(it basically tells that the input is in kB(1024B) insted of B
Output:
2.9G
For private repos pass a token as a header
-H "Authorization: token GITHUB_TOKEN"
replace GITHUB_TOKEN with a github token that has access to private repos
https://command-not-found.com/jq
https://command-not-found.com/numfmt