Skip to content

Instantly share code, notes, and snippets.

@BaksiLi
Last active August 12, 2023 06:58
Show Gist options
  • Save BaksiLi/5f6b9c4fc0c2b70ab05ab27c4aab80ff to your computer and use it in GitHub Desktop.
Save BaksiLi/5f6b9c4fc0c2b70ab05ab27c4aab80ff to your computer and use it in GitHub Desktop.
Add import (`load_func`) online scripts to zsh/bash
load_func() {
local CMD_NAME="$1"
local SCRIPT_URL="$2"
local SAFETY_CHECK="${3:-true}"
local script=$(curl -fsSL $SCRIPT_URL)
if [[ "$SAFETY_CHECK" == "true" && $script =~ "rm " ]]; then
echo "Failed to load command $CMD_NAME: Harmful command detected in script."
return 1
else
eval "$script"
if ! command -v $CMD_NAME > /dev/null; then
echo "Failed to load command $CMD_NAME."
return 1
fi
fi
return 0
}
@BaksiLi
Copy link
Author

BaksiLi commented Aug 12, 2023

If you use Zinit plugin manager for ZSH, you can try this install_compsnip.zsh.

Same functionality is achieved by:

install_gist_snippet 'BaksiLi/zinit-remove' 'BaksiLi/498c63a1cd12e3dd1f6b7426206c33ed'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment