Last active
February 26, 2022 19:12
-
-
Save Piotr1215/1df57ae2da3c8106cc99938c1737bc01 to your computer and use it in GitHub Desktop.
Get repos locally using gh CLI with gh s plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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