diff --git a/.local/bin/scripts/fgh b/.local/bin/scripts/fgh new file mode 100755 index 0000000..dc795df --- /dev/null +++ b/.local/bin/scripts/fgh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Fuzzy cloner of GitHub repos. +# Usage: fgh + +[ "$1" ] && user="$1" || user="$USER" + +data() { + curl -s -n "https://api.github.com/users/$user/repos?per_page=100&page=1" +} + +[ "$(data | grep "Not Found")" ] && { echo "[E] Incorrect user."; exit 1 ;} + +repos() { + data | jq --stream -r 'select(.[0][1] == "full_name") | .[1]' +} + +[ ! "$(repos)" ] && { echo "This user don't have any public repo!"; exit 0 ;} + +chosen="$(repos | fzf --reverse --height=30%)" + +[ ! "$chosen" ] && exit 0 + +git clone git@github.com:"$chosen"