Created
July 24, 2022 17:34
-
-
Save kiliman/0e5a18d57dcdecbc4158e900aea5a4bf to your computer and use it in GitHub Desktop.
Shell script to download Remix example from GitHub without having to clone entire repo
This file contains hidden or 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 | |
if [ -z "$1" ]; then | |
echo USAGE: "$0" EXAMPLE | |
exit | |
fi | |
url="https://github.com/remix-run/remix/examples/$1" | |
# default to branch master | |
branch=main | |
# split url by / | |
IFS=/ read -r -a parts <<< "$url" | |
user="${parts[3]}" | |
repo="${parts[4]}" | |
# get folder segments starting at 5 to end of array | |
folders=("${parts[@]:5}") | |
folder="$(IFS=/; printf '%s' "${folders[*]}")" | |
# strip off parent folders above specific folder | |
strip="$((${#parts[@]} - 5))" | |
# download git archive | |
# pipe to tar to extract (strip off parent folder) | |
curl -L "https://github.com/${user}/${repo}/archive/${branch}.tar.gz" \ | |
| tar -xv --strip-components=${strip} "${repo}-${branch}/${folder}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment