Skip to content

Instantly share code, notes, and snippets.

@Piotr1215
Last active February 26, 2022 19:12
Show Gist options
  • Save Piotr1215/1df57ae2da3c8106cc99938c1737bc01 to your computer and use it in GitHub Desktop.
Save Piotr1215/1df57ae2da3c8106cc99938c1737bc01 to your computer and use it in GitHub Desktop.
Get repos locally using gh CLI with gh s plugin
#!/usr/bin/env bash
# Find a repo for my user and cd into it, clone and cd if not found on disk
function repo() {
# If repo name not provided, prompt for it rather than error out
if [[ -z "$1" ]]; then
export repo=$(ghs -u Piotr1215 | sed 's:.*/::')
else
export repo=$(ghs -u Piotr1215 $1 | sed 's:.*/::')
fi
if [[ -z "$repo" ]]; then
echo "Repository not found"
elif [[ -d /home/decoder/dev/$repo ]]; then
echo "Repository found locally, entering"
cd /home/decoder/dev/$repo
else
echo "Repository not found locally, cloning"
gh repo clone $repo /home/decoder/dev/$repo
cd /home/decoder/dev/$repo
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment