[nushell] Quote paths inserted by CTRL-T (#4919)

- Selections were appended to the command line as-is, so a path with
  spaces became several arguments and syntax in a file name was left
  unquoted for the parser
- Read the selection with --print0 and serialize each path with `to nuon`,
  so each one stays a single string literal
- Skip the insertion entirely when nothing was selected
This commit is contained in:
Junegunn Choi
2026-09-11 21:46:03 +09:00
committed by GitHub
parent b224480a98
commit fe04475d24
3 changed files with 53 additions and 4 deletions
+14 -4
View File
@@ -138,7 +138,7 @@ let ctrl_t = {
{
send: executehostcommand
cmd: "
let fzf_opts = (__fzf_defaults '--reverse --walker=file,dir,follow,hidden --scheme=path' $'($env.FZF_CTRL_T_OPTS) -m');
let fzf_opts = (__fzf_defaults '--reverse --walker=file,dir,follow,hidden --scheme=path' $'($env.FZF_CTRL_T_OPTS) -m --print0');
let fzfcmd = (__fzfcmd);
let fzf_args = ($fzfcmd | skip 1);
let ctrl_t_cmd = ($env.FZF_CTRL_T_COMMAND? | default null);
@@ -149,9 +149,19 @@ let ctrl_t = {
let sh_cmd = [$ctrl_t_cmd '|' $fzf_cmd_str] | str join ' ';
with-env { FZF_DEFAULT_OPTS: $fzf_opts, FZF_DEFAULT_OPTS_FILE: '' } { ^sh -c $sh_cmd }
};
let result = ($result | str replace --all (char newline) ' ' | str trim);
commandline edit --append $result;
commandline set-cursor --end
# Serialize each path as a Nushell string literal, so that syntax
# in a file name is not evaluated when the line is executed.
let result = (
$result
| split row (char nul)
| where {|path| $path != ''}
| each {|path| $path | to nuon}
| str join ' '
);
if ($result | is-not-empty) {
commandline edit --append $'($result) ';
commandline set-cursor --end
}
"
}
]