Skip to content

Instantly share code, notes, and snippets.

@hkoba
Created January 25, 2014 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkoba/8614092 to your computer and use it in GitHub Desktop.
Save hkoba/8614092 to your computer and use it in GitHub Desktop.
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