hedyhli / starcli

:sparkles: Browse trending GitHub projects from your command line
https://pypi.org/project/starcli/
MIT License
547 stars 50 forks source link

Feat: View the main README.md from the terminal as well #93

Closed d84-n1nj4 closed 1 year ago

d84-n1nj4 commented 3 years ago

Description Hi all,

I put together this bash script that let's you view the main README.md for GitHub repos you find with this tool. This will only work with output format list. Let's say you run starcli -L list -t deep-learning -p '>=2020-11-20' -r 10 -l pytorch and you decide you want to look at one of those ten repos and view the README.md without leaving the terminal, and one of those repos is fastai/fastbook.

You'd create a shell script, say in your ~/Downloads path with vim viewREADME.sh and insert the following code:

#!/bin/bash

url=$1;
program=$2
base="https://raw.githubusercontent.com/";
file="README.md";
end="/master/README.md"

cd ~/Downloads;

curl -H 'Authorization: token INSERT_PERSONAL_TOKEN' \
  -H 'Accept: application/vnd.github.v3.raw' \
  -O \
  -L "${base}${url}${end}"

sleep 5

if [ ${program} = "glow" ]; then
    ${program} -s dark ${file}
else
    ${program} ${file}
fi

sleep 2

rm ${file}

This script has a couple prerequisites. You need to install a program like glow or grip to handle the markdown file. Also, you'll need to get an access token from GitHub. You can follow this guide for the token Create a personal access token. Then update the code above with your personal access token. Once that is complete, you'd run ./viewREADME.sh fastai/fastbook glow to view the README.md for that repo.

I'm sure this script could be cleaned up a bit, or further customized, but it works for my purposes.

Why do you think it would be a good idea?

Easy access to the README.md file.


Checklist