Skip to content

Instantly share code, notes, and snippets.

@gabrielfalcao
Last active April 19, 2026 21:01
Show Gist options
  • Select an option

  • Save gabrielfalcao/561106cbb582256c10a7978570c46081 to your computer and use it in GitHub Desktop.

Select an option

Save gabrielfalcao/561106cbb582256c10a7978570c46081 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -umeTE
set +f
set -o pipefail
export IFS=$'\n'
declare -a owner_slash_repo_list=()
declare -a github_repo_urls_to_clone=(
"cross-rs/cross"
"cross-rs/cross-toolchains"
"https://github.com/CPunisher/swc-experimental"
"https://github.com/NULL-header/assert-parse"
"https://github.com/Schniz/fnm"
"https://github.com/addfox/addfox"
"https://github.com/joelself/tomllib"
"https://github.com/johnthagen/min-sized-rust"
"https://github.com/randerson112/craft"
"https://github.com/raviqqe/schemat#"
"https://github.com/rui314/mold"
"https://github.com/rust-osdev/x86_64"
"https://github.com/tattoy-org/tattoy"
"https://github.com/tpoechtrager/osxcross"
)
export IFS=$'\n'
owner_slash_repo_list=($(echo "${github_repo_urls_to_clone[*]}" | sed -E -n 's,^((https://github.com)?[/]?([a-zA-Z0-9]+[a-zA-Z0-9_-]*?[a-zA-Z0-9]?)/([a-zA-Z0-9]+[a-zA-Z0-9_.-]*?[a-zA-Z0-9_.-]*[^/#?&]*))([/#?&]+)?$,\n\3/\4\n,gp'))
declare -- script_name="$(basename "${BASH_SOURCE[0]}")"
declare -- script_path="$(2>/dev/random 1>/dev/random cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
declare -- this_script_path="${script_path}/${script_name}"
declare -- stderr="$(mktemp)"
on_exit() {
set +x
bash -c "exec 1>&2;
set -umeTE; set +f; set -o pipefail;
rm -f ${stderr@Q} &
disown -a
"
}
on_ctrlc() {
1>&2 echo -e "\x1b[1;38;2;253;67;83m\rAborted with Ctrl-C\x1b[0m"
exit 130
}
trap on_exit exit
trap on_ctrlc hup
trap on_ctrlc int
trap on_ctrlc bus
trap on_ctrlc segv
trap on_ctrlc sys
declare -- owner=""
declare -- owner_and_repo=""
declare -- repo=""
declare -- name=""
declare -- value=""
declare -- target=""
declare -- clone_url=""
declare -- target_path=""
declare -A owner_repo_to_repo_mapping=()
declare -A owner_repo_to_owner_mapping=()
declare -- today=$(date -u +'%Y-%m-%d')
for owner_and_repo in ${owner_slash_repo_list[@]}; do
owner=$(cut -d/ -f1 <<<"${owner_and_repo%%/}")
repo=$(cut -d/ -f2 <<<"${owner_and_repo%%/}")
owner_repo_to_repo_mapping["${owner_and_repo}"]="${repo%%/}"
owner_repo_to_owner_mapping["${owner_and_repo}"]="${owner%%/}"
1>&2 echo -e "\x1b[1;38;2;145;219;105mrepo \x1b[1;38;2;48;225;185m${repo} \x1b[1;38;2;234;173;237mis owned \x1b[1;38;2;145;219;105mby \x1b[1;38;2;252;167;144m${owner}\x1b[0m"
1>&2 echo -e " \x1b[1;38;2;145;219;105m\x1b[1;38;2;48;225;185mhttps://github.com\x1b[1;38;2;234;173;237m/\x1b[1;38;2;246;129;129m${repo}\x1b[1;38;2;145;219;105m/\x1b[1;38;2;252;167;144m${owner}\x1b[1;38;2;251;185;84m.git\x1b[0m"
done
for owner_and_repo in ${!owner_repo_to_repo_mapping[@]}; do
repo=${owner_repo_to_repo_mapping["${owner_and_repo}"]}
owner=${owner_repo_to_owner_mapping["${owner_and_repo}"]}
clone_url="https://github.com/${owner_and_repo}.git"
target="${script_path}/${repo}"
if [ ! -e "${target}" ]; then
1>&2 echo -e "\x1b[1;38;2;145;219;105m${owner_and_repo} \x1b[1;38;2;251;185;84m-> \x1b[1;38;2;145;219;105m${target}\x1b[0m"
git clone "${clone_url}" "${target}"
else
1>&2 echo -e "\x1b[1;38;2;240;79;120mskipping \x1b[1;38;2;143;211;255mgithub.com/${owner_and_repo} \x1b[1;38;2;240;79;120mbecause \x1b[1;38;2;252;167;144m${target} \x1b[1;38;2;240;79;120malready exists\x1b[0m"
fi
declare -- tryout_path="${HOME}/workbench/${today}/tryouts"
declare -- tryout_owner_repo_path="${tryout_path}/github__${owner}__${repo}"
if [ ! -e "${tryout_path}" ]; then
1>&2 echo -e "\x1b[1;38;2;249;194;43mcreating \x1b[1;38;2;234;173;237mtryout \x1b[1;38;2;249;194;43mpath \x1b[1;38;2;199;220;208m${tryout_path}\x1b[0m"
mkdir -p "${tryout_path}"
fi
if [ ! -e "${tryout_owner_repo_path}" ]; then
1>&2 echo -e "\x1b[1;38;2;145;219;105mlinking \x1b[1;38;2;48;225;185m${target_path} \x1b[1;38;2;234;173;237mtryout \x1b[1;38;2;145;219;105mpath \x1b[1;38;2;252;167;144m${tryout_path}\x1b[0m"
ln -s "${target}" "${HOME}/workbench/${today}/tryouts/github__${owner}__${repo}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment