[Home] Zsh logo

match-echotc

Zsh Wizard

Download match-echotc Return to Examples
  1. #!/usr/local/bin/zsh
  2. #
  3. # match-echotc
  4. # sets the array "reply" with the termcap entries given in $TERMCAP.
  5. #
  6. # This sed script first removes the first termcap entry because it is
  7. # the name of the termcap entry. Then, in the loop 'start', it makes a
  8. # copy of the pattern space into the hold space, removes the first entry
  9. # from the hold space, leaves just the two-letter entry in the pattern space
  10. # (not its value), prints it if it isn't made up of just spaces and tabs,
  11. # replaces the pattern space with the slightly shortened hold space,
  12. # resets the replacement-checking by a dummy jump, then reads in the
  13. # next line of input if these are no colons left in the pattern space.
  14. # regardless, it jumps back to the 'start' label. When EOF is reached,
  15. # ends.
  16. local excl=!
  17. reply=( $(echo $TERMCAP | sed -n 's/[^:]*://
  18. :start
  19. h;s/^[^:]*://;x;s/^\([^=#:]*\).*$/\1/;/^[ ]*$/'$excl'p;g;t reset
  20. :reset
  21. s/:/:/;t start
  22. n;b start') )