#!/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"