Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: s/pattern/pattern/g on the commandline ?



On Sat, 25 Feb 2012 19:24:50 +0100
<meino.cramer@xxxxxx> wrote:
> Is there any way to submit commands like
> 's/<searched>/<replacement>/g' for being applied the whole commandline
> in one go?

Just as a postscript, it's worth noting the ZLE widgets replace-string
(which can also be loaded under the names replace-pattern or
replace-regexp) and replace-string-again.  This allows you to do this
interactively from the command line.  See the zshcontrib manual page.

I use


# actually autoloaded
zlewidget() {
  # bindkey KEY to new WIDGET, possibly implemented by optional FUNCTION.
  # FUNCTION defaults to WIDGET and will be marked for autoload -Uz.

  local key=$1
  local widget=$2
  local function=${3:-$2}

  autoload -Uz $function
  zle -N $widget $function
  bindkey $key $widget
}
zlewidget "\e%" replace-regexp replace-string
zlewidget '\e&' replace-regexp-again replace-string-again


(though in fact I don't tend to use \e& because (i) I rarely need to
replace the same thing multiple times (ii) I can't remember what the
last thing I replaced is anyway.)

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog



Messages sorted by: Reverse Date, Date, Thread, Author