Max Mikhanosha | 4 Aug 07:09

zle widgets coolness: pipe command template

Wrote my first zle widget, thought I'll share:

# define-pipe-widget <widget-name> "template1" "template2" ....
#
# Defines "pipe widget" templates. Its hard to describe the best way
# is through an example:
#
# define-pipe-widget insert_grep  "grep \"@@@\"" "grep -i \"@@@\"" "grep @@@" 
# define-pipe-widget insert_head "head" "head\n"
#
# bindkey "\M-g" insert_grep
# bindkey "\M-h" insert_head
#
# Now pressing Alt-G will insert (| represents cursor position)
#
# On empty command line: grep "|"
#
# On non-empty command line: <old cmdline> | grep "|"
#
# Pressing Alt-G one more time cycles through choices
# ie:
#  ... |  grep "|"
#  ... | grep -i "|"
#  ... | grep
#  
# If template has \n in the end, then it will be auto-accepted:
# 
#      Alt-H does: ... | head <cursor here>
#  2nd Alt-H does  ... | head<Enter>
#
(Continue reading)


Gmane