Edit 'fgh' script

- Add bindings to open in browser and clone via https.
- Cosmetic changes.
This commit is contained in:
Wiktor Zykubek 2020-05-18 09:38:33 +02:00
parent c2bbdcbd3a
commit a73b6e1a45

View File

@ -1,7 +1,14 @@
#!/bin/sh #!/bin/sh
# Fuzzy cloner of GitHub repos. # Fuzzy cloner of GitHub repos.
# Usage: fgh <user> # Usage: fgh <user>
# When you don't specify user then user=$USER.
# Bindings:
# enter - clone via ssh
# ctrl+h - clone via https
# ctrl+b - open in browser
[ "$1" ] && user="$1" || user="$USER" [ "$1" ] && user="$1" || user="$USER"
@ -9,16 +16,21 @@ data() {
curl -s -n "https://api.github.com/users/$user/repos?per_page=100&page=1" 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 ;} if data | grep -q "Not Found"; then
echo "[E] Incorrect user."
exit 1
fi
repos() { repos() {
data | jq --stream -r 'select(.[0][1] == "full_name") | .[1]' data | jq --stream -r 'select(.[0][1] == "full_name") | .[1]'
} }
[ ! "$(repos)" ] && { echo "This user don't have any public repo!"; exit 0 ;} [ ! "$(repos)" ] && {
echo "This user don't have any public repo!"
exit 1
}
chosen="$(repos | fzf --reverse --height=30%)" repos | fzf --reverse --height=40% \
--bind "enter:execute(git clone git@github.com:{})" \
[ ! "$chosen" ] && exit 0 --bind "ctrl-h:execute(git clone https://github.com/{})" \
--bind "ctrl-b:execute($BROWSER https://github.com/{})"
git clone git@github.com:"$chosen"