Skip to content

Instantly share code, notes, and snippets.

View optisistem's full-sized avatar

Optisistem optisistem

View GitHub Profile
@optisistem
optisistem / autoload.sh
Created January 28, 2021 14:56 — forked from sergioro9/autoload.sh
Bash autoload
# autoload bash scripts. Much faster than `source script.sh`
# usage: autoload script.sh
autoload() {
[ -f "$1" ] || { echo "Usage ${FUNCNAME[0]} <filename>"; return 1;}
filename="$1"
loadname="$(sed 's:\..*::' <<< $(basename $filename))"
if [ -z "$(eval echo \${${loadname}_loaded})" ]; then
functions=$(command grep -o "^[a-zA-Z0-9_:]* *()" $filename | sed 's/()//')
for f in $functions; do
eval "