On Wed, Jan 31, 2024 at 09:07:51PM +0000, Simon Ser wrote:
> Hm, but then this doesn't handle quotes in the filename. What I mean was> something like:>> exec.Command("sh", "-c", editor + ` "$@"`, "--", file.Name())
I really could not find a solution that would work for all edge cases.
Your proposal above works for quotes but fails if the path starts with a dash:
export TMPDIR="-hut"
Re: Re: [PATCH v2] pager/editor: Invoke command with "sh -c"
On Thursday, February 1st, 2024 at 14:09, Thorben Günther <admin@xenrox.net> wrote:
> Your proposal above works for quotes but fails if the path starts with a dash:> export TMPDIR="-hut"
Seems like git does it like I suggested [1].
TBH I'm tempted to just ask users to use an intermediary shell script if
they want to spawn an editor with a shell.
[1]: https://github.com/git/git/blob/bc7ee2e5e16f0d1e710ef8fab3db59ab11f2bbe7/run-command.c#L295
On Thu, Feb 01, 2024 at 02:13:50PM +0000, Simon Ser wrote:
> Seems like git does it like I suggested [1].>> TBH I'm tempted to just ask users to use an intermediary shell script if> they want to spawn an editor with a shell.>> [1]: https://github.com/git/git/blob/bc7ee2e5e16f0d1e710ef8fab3db59ab11f2bbe7/run-command.c#L295
When invoked from the terminal your suggestion works perfectly fine for
all 3 tested edge cases (space, quotes, starting with dash).
Just with exec.Command it fails for "-test". Seems like go parses it a
bit differently...
My favourite solution would be to just add shlex to what we have right
now and call it a day.
On Thursday, February 1st, 2024 at 15:20, Thorben Günther <admin@xenrox.net> wrote:
> On Thu, Feb 01, 2024 at 02:13:50PM +0000, Simon Ser wrote:> > > Seems like git does it like I suggested 1.> > > > TBH I'm tempted to just ask users to use an intermediary shell script if> > they want to spawn an editor with a shell.> > > When invoked from the terminal your suggestion works perfectly fine for> all 3 tested edge cases (space, quotes, starting with dash).> Just with exec.Command it fails for "-test". Seems like go parses it a> bit differently...
Weird, it consistently fails from the command line for me. Tried both
dash and bash.
What seems to work is sh -c -- '%s "$@"' '-asdf'.
> My favourite solution would be to just add shlex to what we have right> now and call it a day.
That'd be fine by me as well.
On Thu, Feb 01, 2024 at 02:30:55PM +0000, Simon Ser wrote:
> Weird, it consistently fails from the command line for me. Tried both> dash and bash.>> What seems to work is sh -c -- '%s "$@"' '-asdf'.
With my zsh setup it works, but yeah dash fails.
Honestly this all feels like too much "magic" to me, so I sent a shlex
patch.