From c2bbdcbd3adc00385ff1e72c64910b1b26a58082 Mon Sep 17 00:00:00 2001 From: Wiktor Zykubek Date: Sun, 17 May 2020 20:24:11 +0200 Subject: [PATCH] Add 'fgh' script --- .local/bin/scripts/fgh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 .local/bin/scripts/fgh 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"