Skip to content

Commit e4d445d

Browse files
committed
feat(nushell): enhance shell completion for vp and vpr commands
1 parent 9da10f5 commit e4d445d

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

  • crates/vite_global_cli/src/commands/env

crates/vite_global_cli/src/commands/env/setup.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,9 @@ def --env --wrapped vp [...args: string@"nu-complete vp"] {
552552
}
553553
}
554554
555-
# Shell completion for nushell (delegates to fish completions)
555+
# Shell completion for nushell (delegates to fish completions dynamically)
556556
def "nu-complete vp" [context: string] {
557-
let fish_comp_path = "__VP_HOME__/vp.fish"
558-
let fish_cmd = $"source '($fish_comp_path)'; complete '--do-complete=($context)'"
557+
let fish_cmd = $"VP_COMPLETE=fish command vp | source; complete '--do-complete=($context)'"
559558
fish --command $fish_cmd | from tsv --flexible --noheaders --no-infer | rename value description | update value {|row|
560559
let value = $row.value
561560
let need_quote = ['\' ',' '[' ']' '(' ')' ' ' '\t' "'" '"' "`"] | any {$in in $value}
@@ -565,10 +564,22 @@ def "nu-complete vp" [context: string] {
565564
} else {$value}
566565
}
567566
}
568-
export def --env --wrapped vpr [...args: string@"nu-complete vp"] { ^vp run ...$args }
567+
# Completion logic for vpr (translates context to 'vp run ...')
568+
def "nu-complete vpr" [context: string] {
569+
let modified_context = ($context | str replace -r '^vpr' 'vp run')
570+
let fish_cmd = $"VP_COMPLETE=fish command vp | source; complete '--do-complete=($modified_context)'"
571+
fish --command $fish_cmd | from tsv --flexible --noheaders --no-infer | rename value description | update value {|row|
572+
let value = $row.value
573+
let need_quote = ['\' ',' '[' ']' '(' ')' ' ' '\t' "'" '"' "`"] | any {$in in $value}
574+
if ($need_quote and ($value | path exists)) {
575+
let expanded_path = if ($value starts-with ~) {$value | path expand --no-symlink} else {$value}
576+
$'"($expanded_path | str replace --all "\"" "\\\"")"'
577+
} else {$value}
578+
}
579+
}
580+
export extern "vpr" [...args: string@"nu-complete vpr"]
569581
"#
570-
.replace("__VP_BIN__", &bin_path_ref)
571-
.replace("__VP_HOME__", &vite_plus_home.as_path().display().to_string());
582+
.replace("__VP_BIN__", &bin_path_ref);
572583
let env_nu_file = vite_plus_home.join("env.nu");
573584
tokio::fs::write(&env_nu_file, env_nu_content).await?;
574585

0 commit comments

Comments
 (0)