romkatv / zsh-defer

Deferred execution of Zsh commands
GNU General Public License v3.0
343 stars 11 forks source link

Added usage tip #4

Closed NightMachinery closed 4 years ago

romkatv commented 4 years ago

This will break calls to zsh-defer with flags. It can also be very confusing because readers who will see zsh-defer being called somewhere will incorrectly assume that zsh-defer actually gets called.

If you want conditional deferral, it's better to use something like this:

function run-or-defer() {
  emulate -L zsh -o extended_glob
  if [[ -o interactive && $DISABLE_DEFER == (#i)(|0|no|false) ]]; then
    zsh-defer -- "$@"
  else
    "$@"
  fi
}

Then use run-or-defer when you want conditional deferral, zsh-defer when you want deferral, and plain commands when you want immediate execution.

I don't think either version would be a net positive contribution to the documentation, so I'll close the PR.