Is there a way ^foo^bar substitution could replace all occurrences of foo in the preceding event like !!:gs/foo/bar/? I've rtfm'd, and it doesn't look like it's doable, but I might've overlooked something. -- FreeBSD 4.4-STABLE 6:26PM up 1 day, 8:52, 14 users, load averages: 0.06, 0.06, 0.02
On Tue, 30 Apr 2002, Roman Neuhauser wrote:
> Is there a way ^foo^bar substitution could replace all occurrences of
> foo in the preceding event like !!:gs/foo/bar/?
Not in the way you think, no. ^foo^bar is, very literally, shorthand for
!!:s^foo^bar -- there's no provision for inserting a `g' to the left of
the leftmost carat.
However, you can always create a special ZLE widget. The following is
pretty much exactly what the history code does:
function insert-bangbang-gs-and-accept {
setopt localoptions noksharrays noshwordsplit
[[ $BUFFER[1] == $histchars[2] ]] && BUFFER='!!:gs'$BUFFER
zle .accept-line
}
zle -N insert-bangbang-gs-and-accept
> thanks, that's just what I needed.
> I use setopt histverify, so I changed the .accept-line to
> .expand-history. but this got me thinking: how would one check for
> an option value in a function?
>
bor@itsrm2% echo $options[histverify]
off
-andrej
> Date: Tue, 30 Apr 2002 09:43:14 -0700 (PDT)
> From: Bart Schaefer <schaefer@brasslantern.com>
> To: Roman Neuhauser <neuhauser@mail.cz>
> cc: zsh users <zsh-users@sunsite.dk>
> Subject: Re: history expansion
>
> On Tue, 30 Apr 2002, Roman Neuhauser wrote:
>
> > Is there a way ^foo^bar substitution could replace all occurrences of
> > foo in the preceding event like !!:gs/foo/bar/?
>
> Not in the way you think, no. ^foo^bar is, very literally, shorthand for
> !!:s^foo^bar -- there's no provision for inserting a `g' to the left of
> the leftmost carat.
>
> However, you can always create a special ZLE widget. The following is
> pretty much exactly what the history code does:
>
> function insert-bangbang-gs-and-accept {
> setopt localoptions noksharrays noshwordsplit
> [[ $BUFFER[1] == $histchars[2] ]] && BUFFER='!!:gs'$BUFFER
> zle .accept-line
> }
> zle -N insert-bangbang-gs-and-accept
thanks, that's just what I needed.
I use setopt histverify, so I changed the .accept-line to
.expand-history. but this got me thinking: how would one check for
an option value in a function?
--
FreeBSD 4.4-STABLE
2:50PM up 7 days, 5:15, 15 users, load averages: 0.17, 0.09, 0.02
> From: Borsenkow Andrej <Andrej.Borsenkow@mow.siemens.ru>
> To: "'Roman Neuhauser'" <neuhauser@mail.cz>,
> "'zsh users'"
> <zsh-users@sunsite.dk>
> Subject: RE: history expansion
> Date: Mon, 6 May 2002 16:43:25 +0400
>
>
> > thanks, that's just what I needed.
> > I use setopt histverify, so I changed the .accept-line to
> > .expand-history. but this got me thinking: how would one check for
> > an option value in a function?
> >
>
> bor@itsrm2% echo $options[histverify]
> off
thanks again!
--
FreeBSD 4.4-STABLE
3:10PM up 7 days, 5:36, 14 users, load averages: 0.01, 0.02, 0.00
hi there, is there a setopt (or another way) that would allow me to do stuff like this: % !!:s/!!3/!-2:s,foo,bar,/ without the need to use variables? -- begin 666 nonexistent.vbs FreeBSD 4.7-RC 12:24PM up 7 days, 19:39, 27 users, load averages: 0.00, 0.01, 0.00 end
On Sep 25, 12:33pm, Roman Neuhauser wrote: } Subject: history expansion } } is there a setopt (or another way) that would allow me to do stuff like } this: } } % !!:s/!!3/!-2:s,foo,bar,/ } } without the need to use variables? So what you want to do is, take the entire line from two commands earlier, do a foo -> bar replacement in that, and then use that as the replacement for the third argument of the immediately preceding command? I'd type C-p C-a M-f M-f M-f M-d !-2:s,foo,bar, and hit enter. There isn't any option or other setting that allows history expansions to be nested in that way. The best you can do is to expand each reference as you go along, by using magic-space or a completion binding; e.g. the above could be obtained by typing something like !!3/!-2:s,foo,bar/<TAB><C-a>!!:s/<RET> (Replace control-a with escape shift-i for vi mode. Hmm, I guess that one might require csh_junkie_history, too.) -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
# schaefer@brasslantern.com / 2002-09-25 23:43:33 +0000: > On Sep 25, 12:33pm, Roman Neuhauser wrote: > } Subject: history expansion > } > } is there a setopt (or another way) that would allow me to do stuff like > } this: > } > } % !!:s/!!3/!-2:s,foo,bar,/ > } > } without the need to use variables? > > So what you want to do is, take the entire line from two commands earlier, > do a foo -> bar replacement in that, and then use that as the replacement > for the third argument of the immediately preceding command? in this example, yes. > I'd type C-p C-a M-f M-f M-f M-d !-2:s,foo,bar, and hit enter. that's what i'm trying to avoid. i'm a history expansion junkie. > There isn't any option or other setting that allows history expansions > to be nested in that way. that's a pitty. > The best you can do is to expand each reference as you go along, by > using magic-space or a completion binding; e.g. the above could be > obtained by typing something like > > !!3/!-2:s,foo,bar/<TAB><C-a>!!:s/<RET> hmm. that's pretty unintuitive for me. not knowing the internals of the history expansion, what is the probability of nested expansion appearing in zsh? -- begin 666 nonexistent.vbs FreeBSD 4.7-RC 12:04PM up 8 days, 19:19, 21 users, load averages: 0.01, 0.04, 0.01 end
On Sep 26, 12:12pm, Roman Neuhauser wrote: } Subject: Re: history expansion } } > } % !!:s/!!3/!-2:s,foo,bar,/ } } > There isn't any option or other setting that allows history expansions } > to be nested in that way. } } not knowing the internals of the history expansion, what is the } probability of nested expansion appearing in zsh? On Sep 26, 11:28am, Peter Stephenson wrote: } } It doesn't look *that* difficult, but it's not completely trivial (some } of the state is currently kept in global variables) so it's a bit of } work In particular I'm concerned about the default (non-CSH_JUNKIE) history behavior: By default, a history reference with no event designator refers to the same event as any preceding history reference on that command line; if it is the only history reference in a command, it refers to the previous command. Within a nested expression, which references "precede" which others? If yet another history reference follows (in a separate word) a nested reference, which of the subexpressions of the nested reference determines which event is used by that second reference? (If this thread continues, it should be moved to zsh-workers.) -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
# schaefer@brasslantern.com / 2002-09-26 17:05:47 +0000: > In particular I'm concerned about the default (non-CSH_JUNKIE) history > behavior: > > By default, a history reference with no event designator refers to the > same event as any preceding history reference on that command line; if > it is the only history reference in a command, it refers to the previous > command. > > Within a nested expression, which references "precede" which others? If yet > another history reference follows (in a separate word) a nested reference, > which of the subexpressions of the nested reference determines which event > is used by that second reference? Being a csh history junkie, this is not for me to decide. :) > (If this thread continues, it should be moved to zsh-workers.) Thanks for considering it! -- begin 666 nonexistent.vbs FreeBSD 4.7-RC 7:27PM up 9 days, 2:42, 11 users, load averages: 0.05, 0.03, 0.00 end
[-- Attachment #1: Type: text/plain, Size: 700 bytes --] hello, history expansion is quite the powerful syntax for re-executing commands from history with various functionalities for automatic transformation. Since it happens before alias expansion it is not possibile to simplify the access to these functionalities though, and one have to remember and type every time the right syntax, and in case of error you have to type everything again. Is that it or am I missing some way to reuse it? I have just thought of a custom widget that could add to $BUFFER a history command of one's choice, are there other ways? Pier Paolo Grassi linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 founder: https://www.meetup.com/it-IT/Machine-Learning-TO
[-- Attachment #1: Type: text/plain, Size: 1030 bytes --] I'm not sure I understand what you mean. Does print -z !! do what you want? Perhaps you want to try out other batch substitutions (e.g. "!:1") before you use "print -z", which enables interactive editing. HTH, Vin On Thu, Feb 20, 2020 at 7:46 AM Pier Paolo Grassi <pierpaolog@gmail.com> wrote: > hello, history expansion is quite the powerful syntax for re-executing > commands from history with various functionalities for automatic > transformation. Since it happens before alias expansion it is not possibile > to simplify the access to these functionalities though, and one have to > remember and type every time the right syntax, and in case of error you > have to type everything again. > Is that it or am I missing some way to reuse it? > I have just thought of a custom widget that could add to $BUFFER a history > command of one's choice, are there other ways? > > Pier Paolo Grassi > linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 > founder: https://www.meetup.com/it-IT/Machine-Learning-TO >
[-- Attachment #1: Type: text/plain, Size: 1621 bytes --] Hi Vin, it does not because: 20-02-20 14:16:45 root@bakeca-vivobook Path: ~ : print -z '!!' 20-02-20 14:16:47 root@bakeca-vivobook Path: ~ : !! print -z '!!' !! is resolved to print -z '!!' If I had used it like you did, as !! unquoted, it would not be aliasable, so I would incur in my original problem thanks Pier Paolo Grassi linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 founder: https://www.meetup.com/it-IT/Machine-Learning-TO Il giorno gio 20 feb 2020 alle ore 14:06 Vin Shelton < acs@alumni.princeton.edu> ha scritto: > I'm not sure I understand what you mean. Does > > print -z !! > > do what you want? Perhaps you want to try out other batch substitutions > (e.g. "!:1") before you use "print -z", which enables interactive editing. > > HTH, > Vin > > On Thu, Feb 20, 2020 at 7:46 AM Pier Paolo Grassi <pierpaolog@gmail.com> > wrote: > >> hello, history expansion is quite the powerful syntax for re-executing >> commands from history with various functionalities for automatic >> transformation. Since it happens before alias expansion it is not >> possibile >> to simplify the access to these functionalities though, and one have to >> remember and type every time the right syntax, and in case of error you >> have to type everything again. >> Is that it or am I missing some way to reuse it? >> I have just thought of a custom widget that could add to $BUFFER a history >> command of one's choice, are there other ways? >> >> Pier Paolo Grassi >> linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 >> founder: https://www.meetup.com/it-IT/Machine-Learning-TO >> >
[-- Attachment #1: Type: text/plain, Size: 1924 bytes --] I still do not understand: what do you want to do? Do you want to create an alias that modifies the history expansion in some particular way? - Vin On Thu, Feb 20, 2020 at 8:19 AM Pier Paolo Grassi <pierpaolog@gmail.com> wrote: > Hi Vin, it does not because: > > 20-02-20 14:16:45 root@bakeca-vivobook Path: ~ > : print -z '!!' > 20-02-20 14:16:47 root@bakeca-vivobook Path: ~ > : !! > print -z '!!' > > !! is resolved to print -z '!!' > If I had used it like you did, as !! unquoted, it would not be aliasable, > so I would incur in my original problem > thanks > > Pier Paolo Grassi > linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 > founder: https://www.meetup.com/it-IT/Machine-Learning-TO > > > Il giorno gio 20 feb 2020 alle ore 14:06 Vin Shelton < > acs@alumni.princeton.edu> ha scritto: > >> I'm not sure I understand what you mean. Does >> >> print -z !! >> >> do what you want? Perhaps you want to try out other batch substitutions >> (e.g. "!:1") before you use "print -z", which enables interactive editing. >> >> HTH, >> Vin >> >> On Thu, Feb 20, 2020 at 7:46 AM Pier Paolo Grassi <pierpaolog@gmail.com> >> wrote: >> >>> hello, history expansion is quite the powerful syntax for re-executing >>> commands from history with various functionalities for automatic >>> transformation. Since it happens before alias expansion it is not >>> possibile >>> to simplify the access to these functionalities though, and one have to >>> remember and type every time the right syntax, and in case of error you >>> have to type everything again. >>> Is that it or am I missing some way to reuse it? >>> I have just thought of a custom widget that could add to $BUFFER a >>> history >>> command of one's choice, are there other ways? >>> >>> Pier Paolo Grassi >>> linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 >>> founder: https://www.meetup.com/it-IT/Machine-Learning-TO >>> >>
[-- Attachment #1: Type: text/plain, Size: 2350 bytes --] something like an alias that could allow me to reuse history expandable expressions, such as !!, !:1, ^cdcd^cddcd and so on Pier Paolo Grassi linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 founder: https://www.meetup.com/it-IT/Machine-Learning-TO Il giorno gio 20 feb 2020 alle ore 14:27 Vin Shelton < acs@alumni.princeton.edu> ha scritto: > I still do not understand: what do you want to do? Do you want to create > an alias that modifies the history expansion in some particular way? > > - Vin > > On Thu, Feb 20, 2020 at 8:19 AM Pier Paolo Grassi <pierpaolog@gmail.com> > wrote: > >> Hi Vin, it does not because: >> >> 20-02-20 14:16:45 root@bakeca-vivobook Path: ~ >> : print -z '!!' >> 20-02-20 14:16:47 root@bakeca-vivobook Path: ~ >> : !! >> print -z '!!' >> >> !! is resolved to print -z '!!' >> If I had used it like you did, as !! unquoted, it would not be aliasable, >> so I would incur in my original problem >> thanks >> >> Pier Paolo Grassi >> linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 >> founder: https://www.meetup.com/it-IT/Machine-Learning-TO >> >> >> Il giorno gio 20 feb 2020 alle ore 14:06 Vin Shelton < >> acs@alumni.princeton.edu> ha scritto: >> >>> I'm not sure I understand what you mean. Does >>> >>> print -z !! >>> >>> do what you want? Perhaps you want to try out other batch substitutions >>> (e.g. "!:1") before you use "print -z", which enables interactive editing. >>> >>> HTH, >>> Vin >>> >>> On Thu, Feb 20, 2020 at 7:46 AM Pier Paolo Grassi <pierpaolog@gmail.com> >>> wrote: >>> >>>> hello, history expansion is quite the powerful syntax for re-executing >>>> commands from history with various functionalities for automatic >>>> transformation. Since it happens before alias expansion it is not >>>> possibile >>>> to simplify the access to these functionalities though, and one have to >>>> remember and type every time the right syntax, and in case of error you >>>> have to type everything again. >>>> Is that it or am I missing some way to reuse it? >>>> I have just thought of a custom widget that could add to $BUFFER a >>>> history >>>> command of one's choice, are there other ways? >>>> >>>> Pier Paolo Grassi >>>> linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 >>>> founder: https://www.meetup.com/it-IT/Machine-Learning-TO >>>> >>>
On 2/20/20, Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
> something like an alias that could allow me to reuse history expandable
> expressions, such as !!, !:1, ^cdcd^cddcd and so on
If you make an alias like normal, but instead of pressing enter, press
^Xa (_expand_alias), it should do what you want. This could then be
extended with a custom widget bound to accept-line that checks if the
current input is one of your special history-aliases and expand it for
you before accepting the line, etc.
skeleton example of the latter,
zle -N accept-line accept-line-history-alias
accept-line-history-alias() {
if [[ $BUFFER = histalias-* ]]; then
zle _expand_alias
fi
zle .$WIDGET
}
if you go this route, you could also use a custom lookup assoc array
instead of using aliases.
--
Mikael Magnusson
[-- Attachment #1: Type: text/plain, Size: 1124 bytes --] that's a nice idea, thanks Mikael Pier Paolo Grassi linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 founder: https://www.meetup.com/it-IT/Machine-Learning-TO Il giorno gio 20 feb 2020 alle ore 16:25 Mikael Magnusson <mikachu@gmail.com> ha scritto: > On 2/20/20, Pier Paolo Grassi <pierpaolog@gmail.com> wrote: > > something like an alias that could allow me to reuse history expandable > > expressions, such as !!, !:1, ^cdcd^cddcd and so on > > If you make an alias like normal, but instead of pressing enter, press > ^Xa (_expand_alias), it should do what you want. This could then be > extended with a custom widget bound to accept-line that checks if the > current input is one of your special history-aliases and expand it for > you before accepting the line, etc. > skeleton example of the latter, > zle -N accept-line accept-line-history-alias > accept-line-history-alias() { > if [[ $BUFFER = histalias-* ]]; then > zle _expand_alias > fi > zle .$WIDGET > } > if you go this route, you could also use a custom lookup assoc array > instead of using aliases. > > -- > Mikael Magnusson >
You can get the aliases expanded automatically by pressing space: Few options: https://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html and http://www.math.cmu.edu/~gautam/sj/blog/20140625-zsh-expand-alias.html GI -- APATHY ERROR: Don't bother striking any key.
[-- Attachment #1: Type: text/plain, Size: 583 bytes --] thanks GI, that's nice too Pier Paolo Grassi linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 founder: https://www.meetup.com/it-IT/Machine-Learning-TO Il giorno ven 21 feb 2020 alle ore 23:51 <gi1242+zsh@gmail.com> ha scritto: > You can get the aliases expanded automatically by pressing space: > > Few options: > > > https://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html > > and > > http://www.math.cmu.edu/~gautam/sj/blog/20140625-zsh-expand-alias.html > > GI > > -- > APATHY ERROR: Don't bother striking any key. >
On Thu, Feb 20, 2020 at 5:20 AM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> 20-02-20 14:16:45 root@bakeca-vivobook Path: ~
> : print -z '!!'
> 20-02-20 14:16:47 root@bakeca-vivobook Path: ~
> : !!
> print -z '!!'
>
> !! is resolved to print -z '!!'
I'm surprised that no one has pointed out that history does not expand
inside single quotes, but it does in double quotes.
print -z "!!"
[-- Attachment #1: Type: text/plain, Size: 827 bytes --] indeed I wasn't aware, but it does not help me since I cannot do this: $a="!!" print -z $a because it still tries to immediately expand the !! thanks though Pier Paolo Grassi linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217 founder: https://www.meetup.com/it-IT/Machine-Learning-TO Il giorno sab 22 feb 2020 alle ore 01:36 Bart Schaefer < schaefer@brasslantern.com> ha scritto: > On Thu, Feb 20, 2020 at 5:20 AM Pier Paolo Grassi <pierpaolog@gmail.com> > wrote: > > > > 20-02-20 14:16:45 root@bakeca-vivobook Path: ~ > > : print -z '!!' > > 20-02-20 14:16:47 root@bakeca-vivobook Path: ~ > > : !! > > print -z '!!' > > > > !! is resolved to print -z '!!' > > I'm surprised that no one has pointed out that history does not expand > inside single quotes, but it does in double quotes. > > print -z "!!" >