Skip to content

Instantly share code, notes, and snippets.

@pawamoy
Last active August 20, 2025 09:21
Show Gist options
  • Save pawamoy/19d61162abaf9fe18df01bc0be265f37 to your computer and use it in GitHub Desktop.
Save pawamoy/19d61162abaf9fe18df01bc0be265f37 to your computer and use it in GitHub Desktop.
Radicle badge, clone from Git
#!/usr/bin/env bash
rid=$(rad inspect --rid) || exit 1
echo "[![radicle](https://img.shields.io/badge/rad-clone-6666FF.svg?style=flat)](https://app.radicle.at/nodes/seed.radicle.at/${rid})"
#!/usr/bin/env bash
BASE58="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
get_git_rid() {
local tempdir="$(mktemp -d)" || exit 1
git clone "${1}" --depth 1 "${tempdir}" || exit 1
local rid="$(grep -Em1 -o "rad:[${BASE58}]+" "${tempdir}/README.md")" || {
echo "rad-git-clone: no Repository ID (RID) found in ${1}'s README" >&2
return 1
}
echo "${rid}"
}
get_gh_rid() {
get_git_rid "https://github.com/${1#gh:}"
}
main() {
local arg
local args=()
local rid
for arg in "$@"; do
case "${arg}" in
rad:*) rid="${arg}" ;;
gh:*) rid="$(get_gh_rid "${arg}")" || exit 1 ;;
-*) args+=("${arg}") ;;
*) rid="$(get_git_rid "${arg}")" || exit 1 ;;
esac
done
if [ -z "${rid}" ]; then
rad clone "${args[@]}"
else
rad clone "${args[@]}" "${rid}"
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment