Skip to content

Instantly share code, notes, and snippets.

@martinratinaud
Created May 26, 2023 06:06
Show Gist options
  • Save martinratinaud/05fe1298bee07a4d04a3e6f3f3cb126d to your computer and use it in GitHub Desktop.
Save martinratinaud/05fe1298bee07a4d04a3e6f3f3cb126d to your computer and use it in GitHub Desktop.
Clone Gist repo to a well named repository
#!/bin/bash
git_clone_gist() {
# The URL of the gist is the first argument to the script
gist_url=$1
# Use the GitHub API to get the name of the first file in the gist
gist_id=$(basename $gist_url)
api_url="https://api.github.com/gists/$gist_id"
json=$(curl -s $api_url)
file_name=$(echo $json | jq -r '.files | keys[0]')
# Clone the gist
git clone $gist_url
# Get the cloned directory name (it is the gist ID)
cloned_dir=$(basename $gist_url .git)
# Rename the directory
new_name="gist_$file_name"
mv $cloned_dir $new_name
# Echo the new directory name, so it can be used in other scripts or command lines
echo $new_name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment