zsh-workers
 help / color / mirror / Atom feed
* [PATCH] Set TMPSUFFIX=.zsh in edit-command-line
@ 2021-05-28 13:35 Akinori MUSHA
  2021-05-29 11:41 ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: Akinori MUSHA @ 2021-05-28 13:35 UTC (permalink / raw)
  To: zsh-workers


[-- Attachment #1.1.1: Type: text/plain, Size: 355 bytes --]

This patch makes the name of a temporary file to have a .zsh suffix so
that the invoked editor will know it's a zsh script.  The .zsh suffix is 
commonly recognized by editors like Emacs, Vim and VS Code.

It's so much easier to edit a command line in a proper editing mode than 
in a plain text mode.

-- 
Akinori MUSHA / https://akinori.org/


[-- Attachment #1.1.2: 0001-Let-EDITOR-invoked-by-edit-command-line-know-it-s-a-.patch --]
[-- Type: text/plain, Size: 760 bytes --]

From 10a2d01b5163e79374060e65f968339a5f3145ae Mon Sep 17 00:00:00 2001
From: Akinori MUSHA <knu@idaemons.org>
Date: Fri, 28 May 2021 22:20:33 +0900
Subject: [PATCH] Let EDITOR invoked by edit-command-line know it's a zsh
 script

---
 Functions/Zle/edit-command-line | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
index 3781244b2..5f7ea321f 100644
--- a/Functions/Zle/edit-command-line
+++ b/Functions/Zle/edit-command-line
@@ -8,6 +8,7 @@
 
 emulate -L zsh
 local left right prebuffer buffer=$BUFFER lbuffer=$LBUFFER
+local TMPSUFFIX=.zsh
 # set up parameters depending on which context we are called from,
 # see below comment for more details
 if (( REGION_ACTIVE )); then
-- 
2.30.1



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 203 bytes --]

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

* Re: [PATCH] Set TMPSUFFIX=.zsh in edit-command-line
  2021-05-28 13:35 [PATCH] Set TMPSUFFIX=.zsh in edit-command-line Akinori MUSHA
@ 2021-05-29 11:41 ` Daniel Shahaf
  2021-05-31 22:54   ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Shahaf @ 2021-05-29 11:41 UTC (permalink / raw)
  To: Akinori MUSHA; +Cc: zsh-workers

Akinori MUSHA wrote on Fri, May 28, 2021 at 22:35:08 +0900:
> This patch makes the name of a temporary file to have a .zsh suffix so
> that the invoked editor will know it's a zsh script.  The .zsh suffix is
> commonly recognized by editors like Emacs, Vim and VS Code.

Thanks for the patch.

Vim already sets the filetype correctly in this case, via the «au
BufNewFile,BufRead zsh*,zlog* call s:StarSetf('zsh')» pattern match in
$VIMRTUNETIME/filetype.vim.  However, I suspect that pattern produces
some false negatives too (e.g., it also matches in cases such as «vim
=(ls)»), so I think this change would be an improvement even for Vim users.

> It's so much easier to edit a command line in a proper editing mode than in
> a plain text mode.

Agreed.  The patch looks good to me, but I haven't time to review or
test it properly, so I'll defer to others on that.

Thanks,

Daniel



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

* Re: [PATCH] Set TMPSUFFIX=.zsh in edit-command-line
  2021-05-29 11:41 ` Daniel Shahaf
@ 2021-05-31 22:54   ` Bart Schaefer
  2021-06-02  3:27     ` Akinori MUSHA
  2021-06-03  7:51     ` Oliver Kiddle
  0 siblings, 2 replies; 5+ messages in thread
From: Bart Schaefer @ 2021-05-31 22:54 UTC (permalink / raw)
  To: Zsh hackers list

On Sat, May 29, 2021 at 4:41 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> Akinori MUSHA wrote on Fri, May 28, 2021 at 22:35:08 +0900:
> > This patch makes the name of a temporary file to have a .zsh suffix
>
> The patch looks good to me, but I haven't time to review or
> test it properly, so I'll defer to others on that.

Unless there's an internal bug with TMPSUFFIX, I can only think of one
way this patch could go wrong, and it's pretty obscure:

Suppose I have a "smart editor" that attempts to decide what program
to run based on file extension (opens .xls as a spreadsheet, .doc with
a word processor, etc.)  Suppose further that this "editor" opens
files ending in ".perl", ".zsh", ".sh", etc. by running the
corresponding interpreter.  Oops, I've just executed the command line
I meant to edit.

This is not entirely far-fetched, if you're on a Mac and have XCode
fully installed, "open /tmp/blablah.zsh" may actually run zsh.

Is this worth worrying about?


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

* Re: [PATCH] Set TMPSUFFIX=.zsh in edit-command-line
  2021-05-31 22:54   ` Bart Schaefer
@ 2021-06-02  3:27     ` Akinori MUSHA
  2021-06-03  7:51     ` Oliver Kiddle
  1 sibling, 0 replies; 5+ messages in thread
From: Akinori MUSHA @ 2021-06-02  3:27 UTC (permalink / raw)
  To: schaefer, zsh-workers


[-- Attachment #1.1.1: Type: text/plain, Size: 1118 bytes --]

On 2021/06/01 7:54, Bart Schaefer wrote:
> Unless there's an internal bug with TMPSUFFIX, I can only think of one
> way this patch could go wrong, and it's pretty obscure:
Thanks for the consideration.
> Suppose I have a "smart editor" that attempts to decide what program
> to run based on file extension (opens .xls as a spreadsheet, .doc with
> a word processor, etc.)  Suppose further that this "editor" opens
> files ending in ".perl", ".zsh", ".sh", etc. by running the
> corresponding interpreter.  Oops, I've just executed the command line
> I meant to edit.
>
> This is not entirely far-fetched, if you're on a Mac and have XCode
> fully installed, "open /tmp/blablah.zsh" may actually run zsh.
>
> Is this worth worrying about?

At least it does not reproduce on my Mac, where Xcode is opened for 
editing the script.  On Ubuntu Desktop, .zsh is associated with gedit 
by default.  If one dares to change that to make double-clicking in 
general unsafe and then set EDITOR to open/start as well, I say they are 
shooting their own foot.

-- 

Akinori MUSHA /https://akinori.org/


[-- Attachment #1.1.2: Type: text/html, Size: 1880 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 203 bytes --]

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

* Re: [PATCH] Set TMPSUFFIX=.zsh in edit-command-line
  2021-05-31 22:54   ` Bart Schaefer
  2021-06-02  3:27     ` Akinori MUSHA
@ 2021-06-03  7:51     ` Oliver Kiddle
  1 sibling, 0 replies; 5+ messages in thread
From: Oliver Kiddle @ 2021-06-03  7:51 UTC (permalink / raw)
  To: Zsh hackers list

On 31 May, Bart Schaefer wrote:
> > Akinori MUSHA wrote on Fri, May 28, 2021 at 22:35:08 +0900:
> > > This patch makes the name of a temporary file to have a .zsh suffix

> This is not entirely far-fetched, if you're on a Mac and have XCode
> fully installed, "open /tmp/blablah.zsh" may actually run zsh.
>
> Is this worth worrying about?

The command it runs comes from a specific editor zstyle, $VISUAL or
$EDITOR, all of which ought to only ever be set to a text editor. It's
always possible that someone shoots themself in the foot in this manner
and it was worth considering. I'd not worry overly unless such a setup
appears to be default for some OS/distribution.

The function already looks to see if it has vim or emacs. Perhaps it
could check for open/xdg-open. I couldn't find a mention of the editor
style in the documentation but if there, a warning could be attached
there.

Anyway, I have pushed the patch.

Oliver


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

end of thread, other threads:[~2021-06-03  7:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-28 13:35 [PATCH] Set TMPSUFFIX=.zsh in edit-command-line Akinori MUSHA
2021-05-29 11:41 ` Daniel Shahaf
2021-05-31 22:54   ` Bart Schaefer
2021-06-02  3:27     ` Akinori MUSHA
2021-06-03  7:51     ` Oliver Kiddle

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ http://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

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

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