Multiselecting from menus

How to make a widget changing argument under cursor

This is an example of how to make a simple widget that modifies the argument the cursor is currently on (or the previous argument if the cursor is between arguments). To simplify, we'll say "current argument" to refer this.

This example will substitute the current argument (which should be a path) by its dirname and bind the function to Alt-q (which by default does the same thing as Ctrl-q, and so is a free shortcut).

In the above code, ${reply[$REPLY]} is the value of the "current argument". We take its dirname of it, set it to the variable $res and we then use modify-current-argument to do the final substitution.

Note : We escaped $res when passing it to modify-current-argument which seems unnecessary, but remember it will be eval'ed, so should $res contain something ressembling an expression (e.g. with a $), you would be in trouble if you forgot escaping.