Skip to content

Instantly share code, notes, and snippets.

@mattriley
Last active March 14, 2020 01:36
Show Gist options
  • Save mattriley/5e5983107e5f81e4e982f34a97eb63b1 to your computer and use it in GitHub Desktop.
Save mattriley/5e5983107e5f81e4e982f34a97eb63b1 to your computer and use it in GitHub Desktop.
Clones and runs a script from a GitHub gist.
# Usage: ./run-gist.sh <GIST ID> <SCRIPT NAME> <SCRIPT ARGS>
# Extract args
gist_id="$1"
script_name="$2"
script_args="${@:3}"
# Clone gist
remote="https://gist.github.com/$gist_id.git"
gist_dir=".gist/$gist_id"
mkdir -p "$gist_dir"
git clone "$remote" "$gist_dir" 2> /dev/null || git -C "$gist_dir" pull
# Run gist script
script_path="$gist_dir/$script_name"
chmod +x "$script_path"
"$script_path" "$script_args"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment