Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] edit-command-line breaks arguments with spaces



Bart Schaefer wrote on Fri, 13 Oct 2017 17:55 -0700:
> On Oct 14, 12:07am, Daniel Shahaf wrote:
> } Subject: Re: [PATCH] edit-command-line breaks arguments with spaces
> }
> } Marco Hinz wrote on Sat, 14 Oct 2017 01:05 +0200:
> } > +      eval "${editor[@]} +${#lines}:$((${#lines[-1]} + 1)) $1";;
> } > +    (*) eval "${editor[@]} $1";;
> } 
> } LGTM, except that $1 should be changed into ${(q)1} due to the eval.
> 
> Wouldn't this work and be preferable to eval?

If $EDITOR is set to "vim -c ''", then:

- current master passes «''» (two characters) for vim's argv[2]

- using eval passes the empty string for vim's argv[2]

- using ${(Q)} elides the "" entirely

So this edge case seems to favour eval.

Come to think of it, using eval will make $EDITOR subject to alias expansions.

> diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
> index 353f260..f77eb35 100644
> --- a/Functions/Zle/edit-command-line
> +++ b/Functions/Zle/edit-command-line
> @@ -15,15 +15,15 @@
>    (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[2]
>  
>    # Open the editor, placing the cursor at the right place if we know how.
> -  local editor=${${VISUAL:-${EDITOR:-vi}}}
> +  local editor=(${(Q)${(z)${VISUAL:-${EDITOR:-vi}}}})
>    case $editor in 
>      (*vim*)
>        integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 ))
> -      ${=editor} -c "normal! ${byteoffset}go" -- $1;;
> +      ${editor} -c "normal! ${byteoffset}go" -- $1;;



Messages sorted by: Reverse Date, Date, Thread, Author