Last active
August 12, 2023 06:58
-
-
Save BaksiLi/5f6b9c4fc0c2b70ab05ab27c4aab80ff to your computer and use it in GitHub Desktop.
Add import (`load_func`) online scripts to zsh/bash
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
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 | |
} |
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
Example:
will load the function in the GitHub gist proxy.zsh.
You can also use a shortened URL, for example:
will load undock.sh (redirected). Pay attention to the third argument. When set to false, it will skip the security check in the script.
Disclaimer: DO NOT load any function/script that you are unsure about. USE WITH CAUTION.