@drfed/drfed 0.1.0 → 0.2.0-dev.605

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/completions/bash/drfed-account +529 -30
  2. package/completions/bash/drfed-migrate +529 -30
  3. package/completions/bash/drfed-server +529 -30
  4. package/completions/bash/drfed-web +529 -30
  5. package/completions/fish/drfed-account.fish +137 -49
  6. package/completions/fish/drfed-migrate.fish +137 -49
  7. package/completions/fish/drfed-server.fish +137 -49
  8. package/completions/fish/drfed-web.fish +137 -49
  9. package/completions/nu/drfed-account.nu +303 -73
  10. package/completions/nu/drfed-migrate.nu +303 -73
  11. package/completions/nu/drfed-server.nu +303 -73
  12. package/completions/nu/drfed-web.nu +303 -73
  13. package/completions/pwsh/drfed-account.ps1 +153 -34
  14. package/completions/pwsh/drfed-migrate.ps1 +153 -34
  15. package/completions/pwsh/drfed-server.ps1 +153 -34
  16. package/completions/pwsh/drfed-web.ps1 +153 -34
  17. package/completions/zsh/_drfed-account +532 -34
  18. package/completions/zsh/_drfed-migrate +532 -34
  19. package/completions/zsh/_drfed-server +532 -34
  20. package/completions/zsh/_drfed-web +532 -34
  21. package/dist/api-mail-parser.d.mts.map +1 -1
  22. package/dist/commands/account-program.d.mts.map +1 -1
  23. package/dist/commands/account.mjs +6 -4
  24. package/dist/commands/account.mjs.map +1 -1
  25. package/dist/commands/migrate-program.d.mts.map +1 -1
  26. package/dist/commands/migrate.mjs +6 -4
  27. package/dist/commands/migrate.mjs.map +1 -1
  28. package/dist/commands/web-program.d.mts.map +1 -1
  29. package/dist/commands/web.mjs +7 -5
  30. package/dist/commands/web.mjs.map +1 -1
  31. package/dist/index.mjs +4 -3
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/jmap-parser.d.mts.map +1 -1
  34. package/dist/logging.d.mts.map +1 -1
  35. package/dist/mail-parser-DyI4wuQp.d.mts.map +1 -1
  36. package/dist/mail-runtime.mjs +1 -2
  37. package/dist/mail-settings-DjWMAUaE.d.mts.map +1 -1
  38. package/dist/mail-settings.mjs +1 -2
  39. package/dist/operations.mjs.map +1 -1
  40. package/dist/package-BRpsF5SF.mjs +6 -0
  41. package/dist/package-BRpsF5SF.mjs.map +1 -0
  42. package/dist/parser-TANGHRjL.d.mts.map +1 -1
  43. package/dist/resources.mjs.map +1 -1
  44. package/package.json +18 -18
  45. package/dist/package-7FOUqcPO.mjs +0 -6
  46. package/dist/package-7FOUqcPO.mjs.map +0 -1
@@ -1,60 +1,187 @@
1
1
 
2
- # Helper to split args respecting quotes and whitespace
2
+ # Helper to split a command line into the arguments Nushell would pass to
3
+ # an external command. Words are found the way Nushell's lexer finds them
4
+ # (quotes and raw strings may contain whitespace), then each word is decoded
5
+ # like an external argument. A final empty argument is added when the line
6
+ # ends in unquoted whitespace, for the word about to be completed.
3
7
  def args-split []: string -> list<string> {
4
- let STATE_NORMAL = 0
5
- let STATE_IN_SINGLE_QUOTE = 1
6
- let STATE_IN_DOUBLE_QUOTE = 2
7
- let STATE_ESCAPE = 3
8
8
  let WHITESPACES = [" " "\t" "\n" "\r"]
9
+ let QUOTES = ["'" '"' "`"]
9
10
 
10
- mut state = $STATE_NORMAL
11
- mut current_token = ""
12
- mut result: list<string> = []
13
- mut prev_state = $STATE_NORMAL
11
+ # Decodes one word. An unterminated word is the one still being typed,
12
+ # so its open quote is taken as if it were closed.
13
+ let decode = {|word: string, unterminated: bool|
14
+ let hashes = if ($word | str starts-with "r#") {
15
+ $word | str replace -r '(?s)^r(#+).*$' '$1'
16
+ } else {
17
+ ""
18
+ }
19
+ if ($hashes | is-not-empty) {
20
+ let prefix = "r" + $hashes + "'"
21
+ let suffix = "'" + $hashes
22
+ let size = ($hashes | str length)
23
+ if ($word | str starts-with $prefix) and ($word | str ends-with $suffix) and (($word | str length) >= ($size * 2 + 3)) {
24
+ $word | str replace $prefix "" | str replace -r ($suffix + '$') ""
25
+ } else if $unterminated and ($word | str starts-with $prefix) {
26
+ $word | str replace $prefix ""
27
+ } else {
28
+ $word
29
+ }
30
+ } else {
31
+ mut result = ""
32
+ mut quote = ""
33
+ mut quoted = ""
34
+ mut escaped = false
35
+ for char in ($word | split chars) {
36
+ if $quote == "" {
37
+ if ($char in $QUOTES) {
38
+ $quote = $char
39
+ $quoted = ""
40
+ } else {
41
+ $result = $result + $char
42
+ }
43
+ } else if $escaped {
44
+ $quoted = $quoted + $char
45
+ $escaped = false
46
+ } else if $char == $quote {
47
+ let body = $quoted
48
+ $result = $result + (if $quote == '"' {
49
+ try { '"' + $body + '"' | from nuon } catch { $body }
50
+ } else {
51
+ $body
52
+ })
53
+ $quote = ""
54
+ } else {
55
+ $quoted = $quoted + $char
56
+ $escaped = ($quote == '"' and $char == '\')
57
+ }
58
+ }
59
+ if $quote != "" {
60
+ let body = $quoted
61
+ $result = $result + (if not $unterminated {
62
+ $quote + $body
63
+ } else if $quote == '"' {
64
+ try { '"' + $body + '"' | from nuon } catch { $body }
65
+ } else {
66
+ $body
67
+ })
68
+ }
69
+ $result
70
+ }
71
+ }
72
+
73
+ mut words: list<string> = []
74
+ mut word = ""
75
+ mut in_word = false
76
+ mut quote = ""
77
+ mut escaped = false
78
+ mut raw_hashes = ""
79
+ mut raw_pending = ""
80
+ mut prev = ""
81
+ mut trailing_space = false
14
82
 
15
83
  for char in ($in | split chars) {
16
- if $state == $STATE_ESCAPE {
17
- $current_token = $current_token + $char
18
- $state = $prev_state
19
- } else if $char == '\\' {
20
- $prev_state = $state
21
- $state = $STATE_ESCAPE
22
- } else if $state == $STATE_NORMAL {
23
- if $char == "'" {
24
- $state = $STATE_IN_SINGLE_QUOTE
25
- } else if $char == '"' {
26
- $state = $STATE_IN_DOUBLE_QUOTE
27
- } else if ($char in $WHITESPACES) {
28
- if ($current_token | is-not-empty) {
29
- $result = $result | append $current_token
30
- $current_token = ""
31
- }
84
+ $trailing_space = false
85
+ if $quote == "#" and $char != "#" and $char != "'" {
86
+ # Not a raw string after all; lex this character normally
87
+ $quote = ""
88
+ }
89
+ if $quote == "r" {
90
+ # Inside a raw string, which ends at ' followed by the same number of #
91
+ if ($raw_pending | is-not-empty) and $char == "#" {
92
+ $raw_pending = $raw_pending + $char
93
+ } else if $char == "'" {
94
+ $raw_pending = $char
32
95
  } else {
33
- $current_token = $current_token + $char
96
+ $raw_pending = ""
34
97
  }
35
- } else if $state == $STATE_IN_SINGLE_QUOTE {
36
- if $char == "'" {
37
- $state = $STATE_NORMAL
98
+ if $raw_pending == ("'" + $raw_hashes) {
99
+ $quote = ""
100
+ $raw_pending = ""
101
+ }
102
+ $word = $word + $char
103
+ } else if $quote == "#" {
104
+ # Between r# and the opening ' of a raw string
105
+ $word = $word + $char
106
+ if $char == "#" {
107
+ $raw_hashes = $raw_hashes + $char
38
108
  } else {
39
- $current_token = $current_token + $char
109
+ $quote = "r"
40
110
  }
41
- } else if $state == $STATE_IN_DOUBLE_QUOTE {
42
- if $char == '"' {
43
- $state = $STATE_NORMAL
111
+ } else if $quote != "" {
112
+ $word = $word + $char
113
+ if $escaped {
114
+ $escaped = false
115
+ } else if $char == $quote {
116
+ $quote = ""
44
117
  } else {
45
- $current_token = $current_token + $char
118
+ $escaped = ($quote == '"' and $char == '\')
119
+ }
120
+ } else if ($char in $WHITESPACES) {
121
+ if $in_word {
122
+ $words = $words | append (do $decode $word false)
123
+ $word = ""
124
+ $in_word = false
46
125
  }
126
+ $trailing_space = true
127
+ } else {
128
+ if ($char in $QUOTES) {
129
+ $quote = $char
130
+ } else if $char == "#" and $prev == "r" {
131
+ $quote = "#"
132
+ $raw_hashes = "#"
133
+ }
134
+ $word = $word + $char
135
+ $in_word = true
47
136
  }
137
+ $prev = $char
48
138
  }
49
- if ($current_token | is-not-empty) {
50
- $result = $result | append $current_token
139
+ if $in_word {
140
+ $words = $words | append (do $decode $word ($quote != ""))
141
+ } else if $trailing_space {
142
+ $words = $words | append ""
143
+ }
144
+ $words
145
+ }
146
+
147
+ # Helper to tell whether Nushell would not read a value back verbatim as a
148
+ # single argument. A leading ! is included because the line editor expands
149
+ # history (e.g., !!) there. With --allow-expansion, a leading tilde and n-dot
150
+ # path segments (e.g., ...) are allowed to expand.
151
+ def needs-quote [--allow-expansion]: string -> bool {
152
+ let value = $in
153
+ let special = ["'" '"' '`' "#" "(" ")" "[" "]" "{" "}" "|" ";" "&" "$" "*" "?" "<" ">"]
154
+ (
155
+ ($value =~ '\s')
156
+ or ($special | any {|c| $value | str contains $c })
157
+ or ($value =~ '^(\+\+|[-+*/])?=$')
158
+ or ($value | str starts-with '!')
159
+ or ((not $allow_expansion) and (
160
+ ($value | str starts-with '~')
161
+ or ($value | split row -r '[/\\]' | any {|s| $s =~ '^\.{3,}$' })
162
+ ))
163
+ )
164
+ }
165
+
166
+ # Helper to quote a value so that Nushell reads it back verbatim as a
167
+ # single argument. The line editor expands history at a ! that follows
168
+ # whitespace even inside quotes, so such a ! is put between two quoted parts,
169
+ # right after a quote, where it is left alone.
170
+ def quote-arg []: string -> string {
171
+ let value = $in
172
+ if ($value | is-empty) or not ($value | needs-quote) {
173
+ $value
174
+ } else if ($value | str contains "'") {
175
+ '"' + ($value | str replace -a '\' '\\' | str replace -a '"' '\"' | str replace -ar '(\s)!' '${1}"!"') + '"'
176
+ } else {
177
+ "'" + ($value | str replace -ar '(\s)!' "${1}'!'") + "'"
51
178
  }
52
- $result
53
179
  }
54
180
 
55
181
  # Completion command that calls back to the CLI
56
182
  export def "nu-complete-drfed-migrate" [context: string] {
57
- # Split context into tokens, handling quotes properly
183
+ # Split context into the arguments Nushell would pass, including an empty
184
+ # one for a new word when the context ends in unquoted whitespace
58
185
  let tokens = $context | args-split
59
186
 
60
187
  # Remove the command name (first token) to get arguments
@@ -64,18 +191,11 @@ export def "nu-complete-drfed-migrate" [context: string] {
64
191
  []
65
192
  }
66
193
 
67
- # If context ends with whitespace, add empty string to represent the new argument
68
- let args_with_empty = if ($context | str ends-with ' ') {
69
- $args | append ''
70
- } else {
71
- $args
72
- }
73
-
74
194
  # Ensure at least one argument (empty string) to get completions not script
75
- let final_args = if ($args_with_empty | is-empty) {
195
+ let final_args = if ($args | is-empty) {
76
196
  ['']
77
197
  } else {
78
- $args_with_empty
198
+ $args
79
199
  }
80
200
 
81
201
  let output = try {
@@ -85,8 +205,10 @@ export def "nu-complete-drfed-migrate" [context: string] {
85
205
  }
86
206
 
87
207
  # Process each line of output
88
- $output | lines | each {|line|
89
- if ($line | str starts-with '__FILE__:') {
208
+ $output | lines | each {|raw_line|
209
+ let literal = ($raw_line | str starts-with '__LITERAL__:')
210
+ let line = if $literal { $raw_line | str substring 12.. } else { $raw_line }
211
+ if (not $literal) and ($line | str starts-with '__FILE__:') {
90
212
  # Parse file completion directive: __FILE__:type:extensions:pattern:hidden
91
213
  let directive = ($line | split row " " | first)
92
214
  let parts = ($directive | split row ':')
@@ -95,6 +217,10 @@ export def "nu-complete-drfed-migrate" [context: string] {
95
217
  let pattern = ($parts | get 3 | str replace -a '%3A' ':' | str replace -a '%25' '%')
96
218
  let hidden = ($parts | get 4) == '1'
97
219
 
220
+ let insertion_prefix = if ($parts | length) > 5 {
221
+ $parts | get 5 | str replace -a '%3A' ':' | str replace -a '%25' '%'
222
+ } else { "" }
223
+
98
224
  # Extract prefix from the last argument if it exists
99
225
  let prefix = if ($final_args | length) > 0 {
100
226
  $final_args | last
@@ -102,18 +228,23 @@ export def "nu-complete-drfed-migrate" [context: string] {
102
228
  ""
103
229
  }
104
230
 
231
+ let insertion_prefix = if ($insertion_prefix | is-not-empty) and ($pattern | str starts-with $insertion_prefix) and ($prefix | str starts-with $insertion_prefix) { $insertion_prefix } else { "" }
232
+ let prefix_length = ($insertion_prefix | str length)
233
+ let pattern = if $prefix_length > 0 { $pattern | str substring $prefix_length.. } else { $pattern }
234
+ let prefix = if $prefix_length > 0 { $prefix | str substring $prefix_length.. } else { $prefix }
235
+
105
236
  # When a pattern is specified, use it as the glob base instead of
106
237
  # the user-typed prefix. If the user has already typed beyond the
107
238
  # pattern (e.g., pattern="src/" and prefix="src/ma"), keep the
108
239
  # prefix for incremental narrowing. Normalize path separators
109
240
  # before comparing so that Windows backslashes match forward slashes
110
241
  # in the transported pattern.
242
+ let is_win = (($nu.os-info.name | str downcase) == "windows")
111
243
  let glob_base = if ($pattern | is-not-empty) {
112
244
  # Normalize separators and leading ./; downcase only on Windows
113
245
  # where filesystems are typically case-insensitive
114
246
  let norm_prefix_raw = ($prefix | str replace -a '\' '/' | str replace -r '^\./' '')
115
247
  let norm_pattern_raw = ($pattern | str replace -a '\' '/' | str replace -r '^\./' '')
116
- let is_win = (($nu.os-info.name | str downcase) == "windows")
117
248
  let norm_prefix = (if $is_win { $norm_prefix_raw | str downcase } else { $norm_prefix_raw })
118
249
  let norm_pattern = (if $is_win { $norm_pattern_raw | str downcase } else { $norm_pattern_raw })
119
250
  # For wildcard patterns, compare only the directory prefix
@@ -132,10 +263,27 @@ export def "nu-complete-drfed-migrate" [context: string] {
132
263
  $prefix
133
264
  }
134
265
 
266
+ # Intersect fixed glob matches with the narrowed prefix candidates.
267
+ # Directory-only suggestions retain their existing navigation behavior.
268
+ let narrow_fixed_glob = ($type != "directory") and ($pattern =~ '[*?]') and ($prefix != $pattern) and ($glob_base == $prefix)
269
+ let fixed_matches = if $narrow_fixed_glob {
270
+ try {
271
+ let fixed_pattern = ($pattern | into glob)
272
+ let include_hidden = $hidden or ($prefix | path basename | str starts-with '.')
273
+ let matches = if $include_hidden { ls -a --directory $fixed_pattern } else { ls --directory $fixed_pattern }
274
+ $matches | each {|item|
275
+ let name = ($env.PWD | path join $item.name | path expand --no-symlink)
276
+ if $is_win { $name | str downcase } else { $name }
277
+ }
278
+ } catch { [] }
279
+ } else { [] }
280
+
135
281
  # If the glob base is a directory without a trailing slash (e.g., "src"),
136
282
  # append one so that ls enumerates its contents instead of matching
137
- # siblings like "src-old"
138
- let glob_base = if ($glob_base | is-not-empty) and ($glob_base | path type) == "dir" and (not ($glob_base | str ends-with "/")) {
283
+ # siblings like "src-old". path expand follows symlinks, so that
284
+ # a symlink to a directory is treated the same way; --no-symlink first
285
+ # resolves .. against the logical $env.PWD as ls does
286
+ let glob_base = if ($glob_base | is-not-empty) and ($glob_base | path expand --no-symlink | path expand | path type) == "dir" and (not ($glob_base | str ends-with "/")) {
139
287
  $glob_base + "/"
140
288
  } else {
141
289
  $glob_base
@@ -144,56 +292,78 @@ export def "nu-complete-drfed-migrate" [context: string] {
144
292
  # Generate file completions based on type.
145
293
  # When the glob base contains wildcard characters, use it as-is;
146
294
  # otherwise append * to treat it as a prefix.
147
- # Note: into glob is required so that ls expands wildcards from a variable
295
+ # Note: into glob is required so that ls expands wildcards from a variable.
296
+ # A literal prefix has its brackets wrapped as [[] and []] so that path
297
+ # text like "report[1]" is not parsed as a glob character class; a
298
+ # wildcard pattern is a glob as a whole, so its brackets stay classes.
148
299
  let has_glob = ($glob_base =~ '[*?]')
149
300
  let ls_pattern = if ($glob_base | is-empty) {
150
301
  "."
151
302
  } else if $has_glob {
152
303
  ($glob_base | into glob)
153
304
  } else {
154
- ($glob_base + "*" | into glob)
305
+ (($glob_base | str replace -a -r '([\[\]])' '[$1]') + "*" | into glob)
155
306
  }
156
307
 
157
308
  # When using a glob pattern, also compute a directory listing pattern
158
- # so that file/any modes can include directories for navigation
309
+ # so that file/any modes can include directories for navigation; its
310
+ # directory part is a literal path
159
311
  let glob_dir_pattern = if $has_glob {
160
312
  let dir_part = ($glob_base | path dirname)
161
313
  let dir = if ($dir_part | is-empty) or ($dir_part == $glob_base) { "." } else { $dir_part }
162
- ($dir + "/*" | into glob)
314
+ (($dir | str replace -a -r '([\[\]])' '[$1]') + "/*" | into glob)
163
315
  } else {
164
316
  null
165
317
  }
166
318
 
167
- # Use ls -a to include hidden files when requested
319
+ # List entries matching a pattern, using ls -a to include hidden
320
+ # files when requested. ls reports every symlink as type "symlink",
321
+ # so classify each one by its target's type instead (path expand
322
+ # follows symlinks); broken or looping symlinks stay "symlink".
323
+ # Join the name to $env.PWD first so that a leading ~ in an entry
324
+ # name is not expanded to a home directory, and resolve .. against
325
+ # the logical $env.PWD (--no-symlink) before following the symlink
326
+ let list_entries = {|pattern|
327
+ (if $hidden { ls -a $pattern } else { ls $pattern }) | each {|item|
328
+ if $item.type == symlink {
329
+ $item | update type ($env.PWD | path join $item.name | path expand --no-symlink | path expand | path type)
330
+ } else {
331
+ $item
332
+ }
333
+ }
334
+ }
335
+
168
336
  let items = try {
169
337
  match $type {
170
338
  "file" => {
171
339
  if ($extensions | is-empty) {
172
- (if $hidden { ls -a $ls_pattern } else { ls $ls_pattern }) | where type == file or type == dir
340
+ (do $list_entries $ls_pattern) | where type == file or type == dir
173
341
  } else {
174
342
  let ext_list = ($extensions | split row ',' | each {|e| $e | str replace -r '^\.' '' })
175
- let all_items = (if $hidden { ls -a $ls_pattern } else { ls $ls_pattern })
343
+ let all_items = (do $list_entries $ls_pattern)
176
344
  let dirs = $all_items | where type == dir
177
345
  let files = $all_items | where type == file | where {|f|
178
- let ext = ($f.name | path parse | get extension)
179
- $ext in $ext_list
346
+ $ext_list | any {|ext|
347
+ $f.name | path basename | str ends-with ('.' + $ext)
348
+ }
180
349
  }
181
350
  $dirs | append $files
182
351
  }
183
352
  },
184
353
  "directory" => {
185
- (if $hidden { ls -a $ls_pattern } else { ls $ls_pattern }) | where type == dir
354
+ (do $list_entries $ls_pattern) | where type == dir
186
355
  },
187
356
  "any" => {
188
357
  if ($extensions | is-empty) {
189
- if $hidden { ls -a $ls_pattern } else { ls $ls_pattern }
358
+ do $list_entries $ls_pattern
190
359
  } else {
191
360
  let ext_list = ($extensions | split row ',' | each {|e| $e | str replace -r '^\.' '' })
192
- let all_items = (if $hidden { ls -a $ls_pattern } else { ls $ls_pattern })
361
+ let all_items = (do $list_entries $ls_pattern)
193
362
  let dirs = $all_items | where type == dir
194
363
  let files = $all_items | where type == file | where {|f|
195
- let ext = ($f.name | path parse | get extension)
196
- $ext in $ext_list
364
+ $ext_list | any {|ext|
365
+ $f.name | path basename | str ends-with ('.' + $ext)
366
+ }
197
367
  }
198
368
  $dirs | append $files
199
369
  }
@@ -208,7 +378,7 @@ export def "nu-complete-drfed-migrate" [context: string] {
208
378
  # even when the glob itself does not match directory names)
209
379
  let items = if ($glob_dir_pattern != null) and ($type != "directory") {
210
380
  let extra_dirs = try {
211
- (if $hidden { ls -a $glob_dir_pattern } else { ls $glob_dir_pattern }) | where type == dir
381
+ (do $list_entries $glob_dir_pattern) | where type == dir
212
382
  } catch {
213
383
  []
214
384
  }
@@ -230,6 +400,17 @@ export def "nu-complete-drfed-migrate" [context: string] {
230
400
  }
231
401
  }
232
402
 
403
+ let filtered = if $narrow_fixed_glob {
404
+ $filtered | where {|item|
405
+ # Any-mode listings already include directory symlinks; keep them
406
+ # navigable without changing their existing completion rendering.
407
+ let navigation_dir = ($item.type == dir) or ($item.type == symlink and (try { ($item.name | path expand | path type) == "dir" } catch { false }))
408
+ let name = ($env.PWD | path join $item.name | path expand --no-symlink)
409
+ let normalized_name = if $is_win { $name | str downcase } else { $name }
410
+ $navigation_dir or ($normalized_name in $fixed_matches)
411
+ }
412
+ } else { $filtered }
413
+
233
414
  # Extract directory prefix to preserve in completion text
234
415
  let dir_prefix = if ($glob_base | is-empty) {
235
416
  ""
@@ -240,19 +421,56 @@ export def "nu-complete-drfed-migrate" [context: string] {
240
421
  if ($parsed.parent | is-empty) { "" } else if ($parsed.parent | str ends-with "/") { $parsed.parent } else { $parsed.parent + "/" }
241
422
  }
242
423
 
243
- # Format file completions
424
+ # Format file completions, quoting names that Nushell would not read
425
+ # back as a single argument
244
426
  $filtered | each {|item|
245
- let name = if $item.type == dir {
246
- $dir_prefix + ($item.name | path basename) + "/"
427
+ let base = if $item.type == dir {
428
+ ($item.name | path basename) + "/"
429
+ } else {
430
+ $item.name | path basename
431
+ }
432
+ let name = $dir_prefix + $base
433
+ # Nushell expands a leading tilde even in a file name, but not after ./
434
+ let spelled = if ($dir_prefix | is-empty) and ($base | str starts-with '~') {
435
+ './' + $base
247
436
  } else {
248
- $dir_prefix + ($item.name | path basename)
437
+ $name
438
+ }
439
+ # A tilde or n-dot prefix typed by the user is meant to be expanded
440
+ # by Nushell, which quoting would prevent, so expand such a prefix
441
+ # here when the value has to be quoted
442
+ let literal_ndots = ($base | str replace -r '[/\\]$' '') =~ '^\.{3,}$'
443
+ let expandable = ($dir_prefix | str starts-with '~') or ($dir_prefix | split row -r '[/\\]' | any {|s| $s =~ '^\.{3,}$' })
444
+ let value = if not ($literal_ndots or ($spelled | needs-quote --allow-expansion)) {
445
+ $spelled
446
+ } else if $expandable {
447
+ let expanded_prefix = ($dir_prefix | path expand --no-symlink)
448
+ let expanded_prefix = if ($expanded_prefix | str ends-with "/") { $expanded_prefix } else { $expanded_prefix + "/" }
449
+ ($expanded_prefix + $base) | quote-arg
450
+ } else {
451
+ $spelled | quote-arg
452
+ }
453
+ if ($insertion_prefix | is-not-empty) {
454
+ # A key before the path keeps any tilde or n-dot segment from
455
+ # being expanded, so quote the whole argument as written and show
456
+ # the key in the menu as well.
457
+ let keyed = $insertion_prefix + $name
458
+ let keyed_value = ($keyed | quote-arg)
459
+ if $keyed_value == $keyed {
460
+ { value: $keyed_value }
461
+ } else {
462
+ { value: $keyed_value, display_override: $keyed }
463
+ }
464
+ } else if $value == $name {
465
+ { value: $value }
466
+ } else {
467
+ { value: $value, display_override: $name }
249
468
  }
250
- { value: $name }
251
469
  }
252
470
  } else {
253
471
  # Regular literal completion - split by tab
254
472
  let parts = ($line | split row " ")
255
- if ($parts | length) >= 2 {
473
+ let record = if ($parts | length) >= 2 {
256
474
  # value\tdescription format
257
475
  { value: ($parts | get 0), description: ($parts | get 1) }
258
476
  } else if ($parts | length) == 1 and ($parts | get 0 | is-not-empty) {
@@ -261,6 +479,18 @@ export def "nu-complete-drfed-migrate" [context: string] {
261
479
  } else {
262
480
  null
263
481
  }
482
+ # Quote values that Nushell would not read back as a single argument,
483
+ # while the menu keeps showing them as they are
484
+ if $record == null {
485
+ null
486
+ } else {
487
+ let value = ($record.value | quote-arg)
488
+ if $value == $record.value {
489
+ $record
490
+ } else {
491
+ $record | upsert value $value | insert display_override $record.value
492
+ }
493
+ }
264
494
  }
265
495
  } | flatten | compact
266
496
  }