zsh-users
 help / color / Atom feed
* Change interactive command into a comment
@ 2019-11-13 18:34 Perry Smith
  2019-11-14  1:15 ` Ben Klein
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Perry Smith @ 2019-11-13 18:34 UTC (permalink / raw)
  To: zsh-users

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

With bash, I got into the following habit.  If I started typing a long command and then decided I didn’t want to execute it right now for some reason, I would hit control-A to get back to the start of the line and then add a # in front and hit return.

This would put the command into history and so later I could recall it, remove the #, and execute the command.

With zsh, when I add the # to the front and hit return I get:

    zsh: bad pattern: #

I found INTERACTIVE_COMMENTS but now I’m curious, what is zsh trying to do with a line starting with # ?  e.g. # echo dog


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2966 bytes --]

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

* Re: Change interactive command into a comment
  2019-11-13 18:34 Change interactive command into a comment Perry Smith
@ 2019-11-14  1:15 ` Ben Klein
  2019-11-14  4:41 ` Danh Doan
  2019-11-15 12:09 ` zzapper
  2 siblings, 0 replies; 9+ messages in thread
From: Ben Klein @ 2019-11-14  1:15 UTC (permalink / raw)
  To: Perry Smith; +Cc: zsh-users

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

The answer to that (assuming extended_glob) is way at the bottom of the
Expansion docs:
http://zsh.sourceforge.net/Doc/Release/Expansion.html#Filename-Generation

To quote directly:

x#
(Requires EXTENDED_GLOB to be set.) Matches zero or more occurrences of the
pattern x. This operator has high precedence; ‘12#’ is equivalent to
‘1(2#)’, rather than ‘(12)#’. It is an error for an unquoted ‘#’ to follow
something which cannot be repeated; this includes an empty string, a
pattern already followed by ‘##’, or parentheses when part of a KSH_GLOB
pattern (for example, ‘!(foo)#’ is invalid and must be replaced by
‘*(!(foo))’).

x##
(Requires EXTENDED_GLOB to be set.) Matches one or more occurrences of the
pattern x. This operator has high precedence; ‘12##’ is equivalent to
‘1(2##)’, rather than ‘(12)##’. No more than two active ‘#’ characters may
appear together. (Note the potential clash with glob qualifiers in the form
‘1(2##)’ which should therefore be avoided.)

*\Ben Klein*
About: https://unhexium.net/about/
Other places online: https://unhexium.net/ll/
Contact me securely: https://keybase.io/robobenklein


On Wed, Nov 13, 2019 at 7:25 PM Perry Smith <pedz@easesoftware.com> wrote:

> With bash, I got into the following habit.  If I started typing a long
> command and then decided I didn’t want to execute it right now for some
> reason, I would hit control-A to get back to the start of the line and then
> add a # in front and hit return.
>
> This would put the command into history and so later I could recall it,
> remove the #, and execute the command.
>
> With zsh, when I add the # to the front and hit return I get:
>
>     zsh: bad pattern: #
>
> I found INTERACTIVE_COMMENTS but now I’m curious, what is zsh trying to do
> with a line starting with # ?  e.g. # echo dog
>
>

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

* Re: Change interactive command into a comment
  2019-11-13 18:34 Change interactive command into a comment Perry Smith
  2019-11-14  1:15 ` Ben Klein
@ 2019-11-14  4:41 ` Danh Doan
  2019-11-14 13:19   ` Perry Smith
  2019-11-14 22:21   ` Oliver Kiddle
  2019-11-15 12:09 ` zzapper
  2 siblings, 2 replies; 9+ messages in thread
From: Danh Doan @ 2019-11-14  4:41 UTC (permalink / raw)
  To: Perry Smith; +Cc: zsh-users

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

On 2019-11-13 12:34:35 -0600, Perry Smith wrote:
> With bash, I got into the following habit.  If I started typing
> a long command and then decided I didn’t want to execute it right
> now for some reason, I would hit control-A to get back to the start
> of the line and then add a # in front and hit return.
> 
> This would put the command into history and so later I could recall
> it, remove the #, and execute the command.

Not an answer for your question, but this piece of code from grml zsh
config may interest you:

-------8<-----------------------

# add a command line to the shells history without executing it
commit-to-history () {
	print -s ${(z)BUFFER}
	zle send-break
}
zle -N commit-to-history
bindkey -M viins "^x^h" commit-to-history
bindkey -M emacs "^x^h" commit-to-history

-------8<------------------------

With this piece of code in your zshrc, you could press C-x C-h to
commit your current command to history without executing it.

-- 
Danh

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: Change interactive command into a comment
  2019-11-14  4:41 ` Danh Doan
@ 2019-11-14 13:19   ` Perry Smith
  2019-11-14 15:40     ` Daniel Shahaf
  2019-11-14 22:21   ` Oliver Kiddle
  1 sibling, 1 reply; 9+ messages in thread
From: Perry Smith @ 2019-11-14 13:19 UTC (permalink / raw)
  To: Danh Doan; +Cc: zsh-users

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



> On Nov 13, 2019, at 10:41 PM, Danh Doan <congdanhqx@gmail.com> wrote:
> 
> On 2019-11-13 12:34:35 -0600, Perry Smith wrote:
>> With bash, I got into the following habit.  If I started typing
>> a long command and then decided I didn’t want to execute it right
>> now for some reason, I would hit control-A to get back to the start
>> of the line and then add a # in front and hit return.
>> 
>> This would put the command into history and so later I could recall
>> it, remove the #, and execute the command.
> 
> Not an answer for your question, but this piece of code from grml zsh
> config may interest you:
> 
> -------8<-----------------------
> 
> # add a command line to the shells history without executing it
> commit-to-history () {
> 	print -s ${(z)BUFFER}
> 	zle send-break
> }
> zle -N commit-to-history
> bindkey -M viins "^x^h" commit-to-history
> bindkey -M emacs "^x^h" commit-to-history
> 
> -------8<------------------------
> 
> With this piece of code in your zshrc, you could press C-x C-h to
> commit your current command to history without executing it.

Cool!  Thanks.

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2966 bytes --]

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

* Re: Change interactive command into a comment
  2019-11-14 13:19   ` Perry Smith
@ 2019-11-14 15:40     ` Daniel Shahaf
  2019-11-14 15:56       ` Danh Doan
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Shahaf @ 2019-11-14 15:40 UTC (permalink / raw)
  To: Perry Smith; +Cc: Danh Doan, zsh-users

Perry Smith wrote on Thu, Nov 14, 2019 at 07:19:01 -0600:
> 
> 
> > On Nov 13, 2019, at 10:41 PM, Danh Doan <congdanhqx@gmail.com> wrote:
> > 
> > On 2019-11-13 12:34:35 -0600, Perry Smith wrote:
> >> With bash, I got into the following habit.  If I started typing
> >> a long command and then decided I didn’t want to execute it right
> >> now for some reason, I would hit control-A to get back to the start
> >> of the line and then add a # in front and hit return.
> >> 
> >> This would put the command into history and so later I could recall
> >> it, remove the #, and execute the command.
> > 
> > Not an answer for your question, but this piece of code from grml zsh
> > config may interest you:
> > 
> > -------8<-----------------------
> > 
> > # add a command line to the shells history without executing it
> > commit-to-history () {
> > 	print -s ${(z)BUFFER}
> > 	zle send-break
> > }
> > zle -N commit-to-history
> > bindkey -M viins "^x^h" commit-to-history
> > bindkey -M emacs "^x^h" commit-to-history
> > 
> > -------8<------------------------
> > 
> > With this piece of code in your zshrc, you could press C-x C-h to
> > commit your current command to history without executing it.
> 
> Cool!  Thanks.

Shouldn't it be «print -rs -- ${(z)BUFFER}»?

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

* Re: Change interactive command into a comment
  2019-11-14 15:40     ` Daniel Shahaf
@ 2019-11-14 15:56       ` Danh Doan
  0 siblings, 0 replies; 9+ messages in thread
From: Danh Doan @ 2019-11-14 15:56 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Perry Smith, zsh-users

On 2019-11-14 15:40:13+0000, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
-------8<-----------------------

# add a command line to the shells history without executing it
commit-to-history () {
	print -rs ${(z)BUFFER}
	zle send-break
}
zle -N commit-to-history
bindkey -M viins "^x^h" commit-to-history
bindkey -M emacs "^x^h" commit-to-history

-------8<------------------------
> > > 
> > > With this piece of code in your zshrc, you could press C-x C-h to
> > > commit your current command to history without executing it.
> 
> Shouldn't it be «print -rs -- ${(z)BUFFER}»?

Yes, that's right, without `-r', escaped character will be evaluated.

Thanks.

-- 
Danh

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

* Re: Change interactive command into a comment
  2019-11-14  4:41 ` Danh Doan
  2019-11-14 13:19   ` Perry Smith
@ 2019-11-14 22:21   ` Oliver Kiddle
  1 sibling, 0 replies; 9+ messages in thread
From: Oliver Kiddle @ 2019-11-14 22:21 UTC (permalink / raw)
  To: zsh-users

Danh Doan wrote:
> With this piece of code in your zshrc, you could press C-x C-h to
> commit your current command to history without executing it.

Another option which covers roughly the same basic use case is the
builtin push-input widget. Rather than use the history, the current
buffer is pushed onto a separate stack and automatically popped
on the next start of the line editor.

There's also push-line and push-line-or-edit which have different
behaviour from secondary (PS2) prompts.

Oliver

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

* Re: Change interactive command into a comment
  2019-11-13 18:34 Change interactive command into a comment Perry Smith
  2019-11-14  1:15 ` Ben Klein
  2019-11-14  4:41 ` Danh Doan
@ 2019-11-15 12:09 ` zzapper
  2019-11-15 13:15   ` Perry Smith
  2 siblings, 1 reply; 9+ messages in thread
From: zzapper @ 2019-11-15 12:09 UTC (permalink / raw)
  To: zsh-users

[-- Warning: decoded text below may be mangled --]
[-- Attachment #0: Type: text/plain, Size: 532 bytes --]

Perry Smith <pedz@easesoftware.com> wrote in
news:AE14DF7F-5C34-4D14-A20A-8356C547E114@easesoftware.com: 

> I found INTERACTIVE_COMMENTS but now Iƒ Tm curious, what is zsh trying
> to do with a line starting with # ?  e.g. # echo dog 

There is also bultin to zsh & bash

<meta>#  

which will autmatically insert # before current command and carriage return

on my system the meta key is Alt.

and yes i always want

setopt interactivecomments  # allows end of command line comments 

-- 
zzapper
https://twitter.com/dailyzshtip


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

* Re: Change interactive command into a comment
  2019-11-15 12:09 ` zzapper
@ 2019-11-15 13:15   ` Perry Smith
  0 siblings, 0 replies; 9+ messages in thread
From: Perry Smith @ 2019-11-15 13:15 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

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



> On Nov 15, 2019, at 6:09 AM, zzapper <david@rayninfo.co.uk> wrote:
> 
> Perry Smith <pedz@easesoftware.com> wrote in
> news:AE14DF7F-5C34-4D14-A20A-8356C547E114@easesoftware.com: 
> 
>> I found INTERACTIVE_COMMENTS but now Iƒ Tm curious, what is zsh trying
>> to do with a line starting with # ?  e.g. # echo dog 
> 
> There is also bultin to zsh & bash
> 
> <meta>#  
> 
> which will autmatically insert # before current command and carriage return
> 
> on my system the meta key is Alt.
> 
> and yes i always want
> 
> setopt interactivecomments  # allows end of command line comments 

Part of my dive into zsh is I changed my keyboard layout.  Leaving out
all the details, I moved my "meta" key from the command key to the
option key (I'm on a Mac).  That has ground my emacs using to be very
slow and awkward but I'm slowly adapting.  I wanted the change because
I wanted e.g. back-word to be the same in emacs and the Terminal.

pedz


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2966 bytes --]

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

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-13 18:34 Change interactive command into a comment Perry Smith
2019-11-14  1:15 ` Ben Klein
2019-11-14  4:41 ` Danh Doan
2019-11-14 13:19   ` Perry Smith
2019-11-14 15:40     ` Daniel Shahaf
2019-11-14 15:56       ` Danh Doan
2019-11-14 22:21   ` Oliver Kiddle
2019-11-15 12:09 ` zzapper
2019-11-15 13:15   ` Perry Smith

zsh-users

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-users

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git