Last active
March 12, 2019 13:48
-
-
Save nexus166/32888166b5434b5cf91a72bfb84a3b9c to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/sh | |
# add this function to your env and then import other scripts with: | |
# eval "$(ghload gist nexus166/msg 581472463579c73e15aa71e6db610cb7)" | |
ghload() { | |
MOD_TYPE=${1}; TOLOAD=${2}; MODULE=${3}; | |
GH_NAME="$(echo ${TOLOAD} | cut -d'/' -f1)"; GH_REPO="$(echo $TOLOAD | cut -d'/' -f2)"; | |
ghGISTS="https://gist.github.com"; ghREPOS="https://raw.githubusercontent.com"; | |
_man() { printf "Usage:\\n\\t\$> ghload gist nexus166/msg 581472463579c73e15aa71e6db610cb7\n\\t\$> ghload repo Spajderix/barc README.md\\n"; }; | |
for v in MOD_TYPE TOLOAD MODULE GH_NAME GH_REPO; do if [ -z $(eval "echo \$$v") ]; then _man; return 127; break; fi; done; | |
GETTER="$(command -v wget || command -v curl || which wget || which curl)"; | |
_getter() { | |
TARGET=${1}; | |
if [ ! -z "$(printf ${GETTER} | grep wget)" ]; then | |
eval "${GETTER} -q -O- ${TARGET}"; | |
elif [ ! -z "$(prinf ${GETTER} | grep curl)" ]; then | |
eval "${GETTER} -fsSL -o- ${TARGET}"; | |
else | |
return 128; | |
fi; | |
}; | |
case ${MOD_TYPE} in | |
g | G | gist | GIST) | |
HASH="${MODULE}"; | |
TOFETCH=$(_getter "${ghGISTS}/${GH_NAME}/${HASH}" | grep Raw | grep -Po '(?<=href=")[^"]*(?=")'); | |
_getter "${ghGISTS}${TOFETCH}"; | |
return $?; | |
;; | |
r | R | repo | REPO) _getter "${ghREPOS}/${GH_NAME}/${GH_REPO}/master/${MODULE}"; return $?;; | |
*) _man; return 127;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment