Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: s/pattern/pattern/g on the commandline ?
- X-seq: zsh-users 16794
- From: Jérémie Roquet <arkanosis@xxxxxxxxx>
- To: meino.cramer@xxxxxx
- Subject: Re: s/pattern/pattern/g on the commandline ?
- Date: Sun, 26 Feb 2012 16:17:00 +0100
- Authentication-results: mr.google.com; spf=pass (google.com: domain of arkanosis@xxxxxxxxx designates 10.180.99.65 as permitted sender) smtp.mail=arkanosis@xxxxxxxxx; dkim=pass header.i=arkanosis@xxxxxxxxx
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=1bbLGJEAtegAuVfNbHQstMdyHCOTZ1bTKKi1LWsKHjA=; b=KFF+PVm2onNPgxMwjKeG7180w+bSckJxP62dBJXF7eljuq6U+ImqOdGiJDOD4/zO9A dtYUc3lLRmqz7f7WDPM9BjQ9K+zTRQ1/w7sNu4jZZncHp6ACvHlm+lde7DQMg8WacpOq OysR4SqNsZakaWqYdO8Co8sC2bF8pzSgUnyNc=
- In-reply-to: <20120226075234.GB3020@solfire>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20120225182450.GA31597@solfire> <CAFOazANiYPxbbLC1UULgUznU_4mA+5W0gYPOKh5LEvAaXdVqBA@mail.gmail.com> <CAFOazAN6DK5eQ9hZBNAm-HwCtsF4B4S9_y8g5mYTwEmZC=h09w@mail.gmail.com> <20120226075234.GB3020@solfire>
Hi,
2012/2/26 <meino.cramer@xxxxxx>:
> ...an additional question:
>
> Suppose I had entered such an ugly looooong commandline about two days
> ago. I did not remember when it was and what the context was.
> And: I have a very looong history file.
>
> I want to recycle that line and do the s//g-trick on it to get a shiny
> new fresh commmandline for the next action.
If the command in your long line is unusual (let's say “makecoffee”),
you could use:
!makecoffee:gs/<before>/<after>
> When I press ^r<pattern> I easily can find that line, it will
> displayed instantly but without its numbering. In the moment the
> commandline is displayed I loose the ability to do the s//g-trick.
>
> Is there a way to browse the commandlines like with ^r only to get its
> numbering to apply the s//g-trick to the choosen line ?
Hacking history-incremental-pattern-search-backward is an option, but
that wouldn't be easy.
Instead, you could use:
fc -lm <pattern>
…to list previous commands matching the pattern, with their numbers.
Also, what I do in non trivial cases, is either:
- use edit-command-line as pointed out by Phil: you just have to
ctrl+r the line you want and then edit it using a real text editor, or
- use a custom widget to run sed (or awk, or perl, or…) on the
current line : you just have to ctrl+r the line you want then to use
whatever key you've bound the widget to to run sed on it.
If you put this in your .zshrc:
function sed-line ()
{
read-from-minibuffer 'Sed: '
if [[ -n $REPLY ]]; then
BUFFER=`echo $BUFFER | sed $REPLY`
fi
}
zle -N sed-line
bindkey "^[e" sed-line
… you can then use meta-e to run a sed command on the line currently
being edited in your shell.
Best regards,
--
Jérémie
Messages sorted by:
Reverse Date,
Date,
Thread,
Author