Skip to content

Instantly share code, notes, and snippets.

@johanhammar
Created April 1, 2024 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanhammar/6f68441b86e2cb584055b03896c1894a to your computer and use it in GitHub Desktop.
Save johanhammar/6f68441b86e2cb584055b03896c1894a to your computer and use it in GitHub Desktop.
Clone GitHub repositories
#!/usr/bin/env bash
if ! command -v fzf &> /dev/null
then
echo "Fzf could not be found. See https://github.com/junegunn/fzf"
exit 1
fi
if ! command -v jq &> /dev/null
then
echo "Jq could not be found. See https://github.com/jqlang/jq"
exit 1
fi
if ! command -v gh &> /dev/null
then
echo "Gh could not be found. See https://cli.github.com/"
exit 1
fi
if [[ -z "${GITHUB_ACCESS_TOKEN}" ]]; then
echo "Must set GITHUB_ACCESS_TOKEN"
exit 1
fi
REPO_URL=$(gh repo list --limit 500 --json name,sshUrl | jq -r '.[] | [.name, .sshUrl] | join(" : ")' | fzf --prompt ' ' --header="Select repository to clone or use CTRL-C to cancel" --bind 'enter:execute(echo {3})+abort')
git clone $REPO_URL
unset REPO_URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment