[Home] Zsh logo

show

Zsh Wizard

Download show Return to Examples
  1. # The function "show" first creates an empty array variable "show", then
  2. # assigns to it the glob expansion (toggled on by `~') of its arguments
  3. # ($*). The alias inserts "noglob" so that any glob pattern I give on
  4. # the command line has its expansion delayed until $~* in the function.
  5. # In conjunction with CSH_NULL_GLOB, when the glob fails, this produces
  6. # zsh: no match
  7. # -after- emptying the previous value of $show. I've considered putting
  8. # "setopt localoptions cshnullglob" in the show() body, but I always have
  9. # it set anyway. In any case, the intent is that $show is non-empty only
  10. # when the glob matches something.
  11. #
  12. # (This does conflict with the MH "show" command, but then, I don't use MH.)
  13. #
  14. # An example of when I use this is when patching zsh sources. Typically I
  15. # apply the patches, then check for which files changed and which patches
  16. # failed:
  17. #
  18. # zsh% ls **/*.{orig,rej}
  19. #
  20. # And finally, if there were no errors, remove all the .orig and .rej files:
  21. #
  22. # zsh% rm -f **/*.{orig,rej}
  23. #
  24. # With "show", rather than repeat the recursive glob, I can just do:
  25. #
  26. # zsh% show **/*.{orig,rej}
  27. # zsh% rm -f $show
  28. function show() { show=(); show=( $~* ); print -rc $show }
  29. alias show "noglob show"