Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add a -quoting switch to evaluate-commands and execute-keys commands #3782

Open
alexherbo2 opened this issue Oct 7, 2020 · 2 comments
Open

Comments

@alexherbo2
Copy link
Contributor

Raw

evaluate-commands -quoting raw %sh{
  echo '"echo" "Tchou"'
}

Error

No such command: '"echo" "Tchou"'

Kakoune

evaluate-commands -quoting kakoune %sh{
  echo '"echo" %[Tchou]'
}

Shell

evaluate-commands -quoting shell %sh{
  printf '"echo" "Tchou"'
}

JSON

evaluate-commands -quoting json %sh{
  jq -n '["echo", "Tchou"]'
}
@krobelus
Copy link
Contributor

krobelus commented Oct 8, 2020

Your -quoting raw is evaluate-commands -verbatim and -quoting kakoune is the default.

The JSON one is interesting because it makes word boundaries very explicit.
I wonder what's the use case.

evaluate-commands -quoting shell %sh{
printf '"echo" "Tchou"'
}

Shell expansion seems out of scope for evaluate-commands (should it expand $() as well?).
It can be done in the sh block, although it's not very nice.

evaluate-commands %sh{
	kakquote() { printf "%s" "$*" | sed "s/'/''/g; 1s/^/'/; \$s/\$/'/"; }

	shell_quoted_command=$(printf '"echo" "Tchou"')

	eval set -- "$shell_quoted_command"
	for arg
	do
		kakquote "$arg"
		printf ' '
	done
}

@alexherbo2
Copy link
Contributor Author

Some programs easily output shell quoted arguments, I assume we should not re-evaluate the resulting string (your $(...) comment).

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants