Skip to content

Commit

Permalink
Update zsh-lazyload.zsh
Browse files Browse the repository at this point in the history
  • Loading branch information
qoomon authored Apr 21, 2023
1 parent 5d685d6 commit 3fc9de4
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions zsh-lazyload.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,20 @@ function lazyload {
local cmd_list=(${@:1:(($seperator_index - 1))});
local load_cmd=${@[(($seperator_index + 1))]};

if [[ ! $load_cmd ]]
then
if [[ ! $load_cmd ]]; then
>&2 echo "[ERROR] lazyload: No load command defined"
>&2 echo " $@"
return 1
fi

# check if lazyload was called by placeholder function
if (( ${cmd_list[(Ie)${funcstack[2]}]} ))
then
if (( ${cmd_list[(Ie)${funcstack[2]}]} )); then
unfunction $cmd_list
eval "$load_cmd"
else
# create placeholder function for each command
local cmd
for cmd in $cmd_list
do
eval "function $cmd {
lazyload $cmd_list $seperator ${(qqqq)load_cmd}
$cmd \"\$@\"
}"
done
for cmd in $cmd_list; eval "function $cmd { lazyload $cmd_list $seperator ${(qqqq)load_cmd} && $cmd \"\$@\" }"
fi
}

Expand Down

0 comments on commit 3fc9de4

Please sign in to comment.