Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/vp_global_cli/src/commands/env/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ def --env --wrapped vp [...args: string@"nu-complete vp"] {

# Shell completion for nushell (delegates to fish completions dynamically)
def "nu-complete vp" [context: string] {
if (%which fish | %is-empty) { return null }
let fish_cmd = $"VP_COMPLETE=fish command vp | source; complete '--do-complete=($context)'"
^fish --command $fish_cmd | %from tsv --flexible --noheaders --no-infer | %rename value description | %update value {|row|
let value = $row.value
Expand All @@ -1022,6 +1023,7 @@ def "nu-complete vp" [context: string] {
}
# Completion logic for vpr (translates context to 'vp run ...')
def "nu-complete vpr" [context: string] {
if (%which fish | %is-empty) { return null }
let modified_context = if ($context =~ '^vpr(?<cwd>\s+-C\s+(?:"[^"]*"|\x27[^\x27]*\x27|\S+))\s') {
$context | %str replace -r '^vpr(?<cwd>\s+-C\s+(?:"[^"]*"|\x27[^\x27]*\x27|\S+))\s' 'vp$cwd run '
} else if ($context =~ '^vpr(?<cwd>\s+-C=?(?:"[^"]*"|\x27[^\x27]*\x27|\S+))\s') {
Expand Down Expand Up @@ -1968,10 +1970,28 @@ mod tests {
assert!(sigil.contains("| %update value {|row|"), "got: {sigil}");
assert!(sigil.contains(r#"("/tmp/vp%home" | %path expand"#), "got: {sigil}");
assert!(sigil.contains("^fish --command"), "got: {sigil}");
assert!(
sigil.contains("if (%which fish | %is-empty) { return null }"),
"got: {sigil}"
);
assert_eq!(
sigil.matches("if (%which fish | %is-empty) { return null }").count(),
2,
"guard should appear in both vp and vpr completers, got: {sigil}"
);

let legacy = render_env_content(EnvShell::Nu, &config, NuSyntax::Legacy);
assert!(legacy.contains("| update value {|row|"), "got: {legacy}");
assert!(legacy.contains("^fish --command"), "got: {legacy}");
assert!(
legacy.contains("if (which fish | is-empty) { return null }"),
"got: {legacy}"
);
assert_eq!(
legacy.matches("if (which fish | is-empty) { return null }").count(),
2,
"guard should appear in both vp and vpr completers, got: {legacy}"
);
assert_eq!(
legacy.replace("/tmp/vp%home", "").matches('%').count(),
0,
Expand Down
Loading