zsh-users
 help / color / mirror / code / Atom feed
* How to see history 'expression' in history rather than the expansion?
@ 2022-06-12 13:17 zzapper
  2022-06-12 16:16 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: zzapper @ 2022-06-12 13:17 UTC (permalink / raw)
  To: Zsh-Users List

Hi

ls IMG_20220612_093815.jpg

cp !$ /tmp

# but when I look at history I obviously see

ls IMG_20220612_093815.jpg

cp IMG_20220612_093815.jpg /tmp

# In this case !$ is trivial but sometimes I do an arbitrarily more 
complex history recall e.g.

cp !?imgxyz?$ /tmp

and I'd like to see that expression in my history (for reference 
purposes or to refine and correct it)

###### I've just remembered/realised that the following widget solves 
that. #####

###### But will still post this just to get any possible further advice 
#####

commit-to-history() {
# store a command in history for reuse w/o executing it
       print -s ${(z)BUFFER}
       zle send-break
}
zle -N commit-to-history
bindkey "^h" commit-to-history # ctrl-h


zzapper





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to see history 'expression' in history rather than the expansion?
  2022-06-12 13:17 How to see history 'expression' in history rather than the expansion? zzapper
@ 2022-06-12 16:16 ` Bart Schaefer
  2022-06-13 10:33   ` Pier Paolo Grassi
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2022-06-12 16:16 UTC (permalink / raw)
  To: Zsh-Users List

On Sun, Jun 12, 2022 at 6:17 AM zzapper <zsh@rayninfo.co.uk> wrote:
>
> ###### I've just remembered/realised that the following widget solves
> that. #####
>
> ###### But will still post this just to get any possible further advice
> #####
>
> bindkey "^h" commit-to-history # ctrl-h

My only further advice would be that ctrl-h may be a somewhat
dangerous binding for this, as you may find yourself in a situation
where backspace and/or delete keys send ctrl-h


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to see history 'expression' in history rather than the expansion?
  2022-06-12 16:16 ` Bart Schaefer
@ 2022-06-13 10:33   ` Pier Paolo Grassi
  2022-06-13 10:43     ` Peter Stephenson
  2022-06-13 16:02     ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: Pier Paolo Grassi @ 2022-06-13 10:33 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 832 bytes --]

Hi Bart, can you elaborate on this? when/why does this happen? I also have
that binding and never caused problems to me (or maybe it did and I didn't
realize/correlated), but of course I prefer to err on the cautious side.

Pier Paolo Grassi


Il giorno dom 12 giu 2022 alle ore 18:17 Bart Schaefer <
schaefer@brasslantern.com> ha scritto:

> On Sun, Jun 12, 2022 at 6:17 AM zzapper <zsh@rayninfo.co.uk> wrote:
> >
> > ###### I've just remembered/realised that the following widget solves
> > that. #####
> >
> > ###### But will still post this just to get any possible further advice
> > #####
> >
> > bindkey "^h" commit-to-history # ctrl-h
>
> My only further advice would be that ctrl-h may be a somewhat
> dangerous binding for this, as you may find yourself in a situation
> where backspace and/or delete keys send ctrl-h
>
>

[-- Attachment #2: Type: text/html, Size: 1467 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to see history 'expression' in history rather than the expansion?
  2022-06-13 10:33   ` Pier Paolo Grassi
@ 2022-06-13 10:43     ` Peter Stephenson
  2022-06-13 16:02     ` Bart Schaefer
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2022-06-13 10:43 UTC (permalink / raw)
  To: Zsh-Users List

> On 13 June 2022 at 11:33 Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
> Il giorno dom 12 giu 2022 alle ore 18:17 Bart Schaefer <
> schaefer@brasslantern.com> ha scritto:
> > My only further advice would be that ctrl-h may be a somewhat
> > dangerous binding for this, as you may find yourself in a situation
> > where backspace and/or delete keys send ctrl-h
>
> Hi Bart, can you elaborate on this? when/why does this happen? I also have
> that binding and never caused problems to me (or maybe it did and I didn't
> realize/correlated), but of course I prefer to err on the cautious side.

Further detail really depends on the terminal(s) you're using.  If you're
happy that all the ones you ever use behave the way you're expecting, you're
probably OK.  But it's very easy to find yourself tweaking something or other
for the first time and finding yourself dumped into an usual terminal or mode
...

Basically just fear, uncertainty and doubt.

pws


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to see history 'expression' in history rather than the expansion?
  2022-06-13 10:33   ` Pier Paolo Grassi
  2022-06-13 10:43     ` Peter Stephenson
@ 2022-06-13 16:02     ` Bart Schaefer
  1 sibling, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2022-06-13 16:02 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Zsh-Users List

On Mon, Jun 13, 2022 at 3:34 AM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> Hi Bart, can you elaborate on this? when/why does this happen?

I've mostly encountered it when using ssh to log in to hosts with
different operating systems (or sometimes even different revisions of
what's supposedly the same OS).  In fact I've hit it so often that my
.zlogin has this:

function stty_backspace {
    local bs
    while (( #bs != 8 && #bs != 127 ))
    do
        print -n 'Press backspace: '
        read -k 1 bs || return 1
        print -nP '\r%E'
    done
    stty erase "$bs"
}

This forces the local erase character to be set to whatever it
perceives the keyboard to be sending for whatever key my muscle-memory
whacks when I want to back up one character, so that editors etc.
match the zsh behavior.  I never change the default zsh bindings that
make ctrl-h and del both backward-delete-char, so in ZLE I don't care.

It's less an issue if you never find yourself moving between a Mac
laptop and a Windows PC and more than one Linux desktop on your local
end and probably not an issue at all if everything is also homogeneous
on the remote end.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-13 16:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-12 13:17 How to see history 'expression' in history rather than the expansion? zzapper
2022-06-12 16:16 ` Bart Schaefer
2022-06-13 10:33   ` Pier Paolo Grassi
2022-06-13 10:43     ` Peter Stephenson
2022-06-13 16:02     ` Bart Schaefer

Code repositories for project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).