Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My Zsh idiom. How to write dryrun behavior in Zsh.
#!/bin/zsh
option_defs+=(
n=o_dryrun
s=o_silent
)
function DO {
if (($#o_dryrun || ! $#o_silent)); then
print -- $argv
fi
if (($#o_dryrun)); then
return
fi
$argv
}
zparseopts -D -K $option_defs
# Then, prefix distructive operation.
DO rm -i *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment