@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,8 +1,31 @@
1
1
 
2
- function __drfed_server_complete
2
+ function __drfed-server_complete
3
3
  set -l tokens (commandline -poc)
4
4
  set -l current (commandline -ct)
5
5
 
6
+ # commandline -poc decodes previous tokens, but commandline -ct returns
7
+ # the current token as typed. Decode its quotes and escapes as well.
8
+ # Keep the token as typed if decoding fails or yields a newline or tab,
9
+ # which completion output cannot carry.
10
+ set -l __raw_current "$current"
11
+ set -l __decoded (string unescape -- "$current")
12
+ or begin
13
+ # string unescape rejects an unfinished trailing backslash. fish
14
+ # keeps it literally inside single quotes, which also keep a " as
15
+ # is, and otherwise waits for the character it escapes.
16
+ set -l __prefix (string replace -r '\\\\$' '' -- "$current")
17
+ set -l __probe (string unescape -- "$__prefix\"")
18
+ set -l __plain (string unescape -- "$__prefix")
19
+ if test "$__probe" = "$__plain\""
20
+ set __decoded (string unescape -- "$current\\")
21
+ else
22
+ set __decoded (string unescape -- "$__prefix")
23
+ end
24
+ end
25
+ and test (count $__decoded) -eq 1
26
+ and not string match -qr '\t' -- "$__decoded"
27
+ and set current "$__decoded"
28
+
6
29
  # Extract previous arguments (skip the command name)
7
30
  set -l prev
8
31
  set -l count (count $tokens)
@@ -15,7 +38,12 @@ function __drfed_server_complete
15
38
 
16
39
  # Process each line of output
17
40
  for line in $output
18
- if string match -q '__FILE__:*' -- $line
41
+ set -l literal 0
42
+ if string match -q '__LITERAL__:*' -- $line
43
+ set line (string sub -s 13 -- $line)
44
+ set literal 1
45
+ end
46
+ if test $literal -eq 0; and string match -q '__FILE__:*' -- $line
19
47
  # Parse file completion directive: __FILE__:type:extensions:pattern:hidden
20
48
  set -l directive (string split \t -- $line)[1]
21
49
  set -l parts (string split ':' -- $directive)
@@ -23,6 +51,34 @@ function __drfed_server_complete
23
51
  set -l extensions $parts[3]
24
52
  set -l pattern (string replace -a '%25' '%' -- (string replace -a '%3A' ':' -- $parts[4]))
25
53
  set -l hidden $parts[5]
54
+ set -l insertion_prefix ""
55
+ if test (count $parts) -ge 6
56
+ set insertion_prefix (string replace -a '%25' '%' -- (string replace -a '%3A' ':' -- $parts[6]))
57
+ end
58
+ set -l saved_current "$current"
59
+ set -l saved_raw_current "$__raw_current"
60
+ set -l prefix_length (string length -- "$insertion_prefix")
61
+ if test $prefix_length -gt 0
62
+ and test (string sub -l $prefix_length -- "$pattern") = "$insertion_prefix"
63
+ and test (string sub -l $prefix_length -- "$current") = "$insertion_prefix"
64
+ set -l start (math $prefix_length + 1)
65
+ set pattern (string sub -s $start -- "$pattern")
66
+ set current (string sub -s $start -- "$current")
67
+ # Keep the raw word aligned so an unquoted key is not mistaken
68
+ # for quoting when comparing it with the decoded value.
69
+ if test (string sub -l $prefix_length -- "$__raw_current") = "$insertion_prefix"
70
+ set __raw_current (string sub -s $start -- "$__raw_current")
71
+ end
72
+ else
73
+ set insertion_prefix ""
74
+ end
75
+
76
+ # path() echoes the current word as its pattern. When that word
77
+ # was quoted or escaped, treat the echo as the typed word rather
78
+ # than as a pattern from the program.
79
+ if test "$current" != "$__raw_current"; and test "$pattern" = "$current"
80
+ set pattern ""
81
+ end
26
82
 
27
83
  # When a pattern is specified, use it as the glob base instead
28
84
  # of the current word. If the user has already typed beyond the
@@ -35,15 +91,13 @@ function __drfed_server_complete
35
91
  # Normalize leading ./ so that ./src/ma matches pattern src/
36
92
  set -l __norm_current (string replace -r '^\./' '' -- "$current")
37
93
  set -l __norm_pattern (string replace -r '^\./' '' -- "$pattern")
38
- # For wildcard patterns, compare only the directory prefix
94
+ # For wildcard patterns, compare only the directory prefix.
95
+ # Use a regex: fish wildcards have no character classes.
96
+ # Only the basename can hold wildcards; a ? or * in a
97
+ # directory name such as What?/ is literal.
39
98
  set -l __compare_pattern "$__norm_pattern"
40
- if string match -q '*[*?]*' -- "$__compare_pattern"
41
- set __compare_pattern (string replace -r '[*?].*' '' -- "$__compare_pattern")
42
- if string match -q '*/*' -- "$__compare_pattern"
43
- set __compare_pattern (string replace -r '/[^/]*$' '/' -- "$__compare_pattern")
44
- else
45
- set __compare_pattern ""
46
- end
99
+ if string match -qr '[*?][^/]*$' -- "$__compare_pattern"
100
+ set __compare_pattern (string replace -r '[^/]*$' '' -- "$__compare_pattern")
47
101
  end
48
102
  set -l __cp_len (string length -- "$__compare_pattern")
49
103
  set -l __nc_len (string length -- "$__norm_current")
@@ -58,14 +112,17 @@ function __drfed_server_complete
58
112
  end
59
113
  end
60
114
 
61
- # Expand tilde prefix for globbing—fish does not expand ~
62
- # inside variable substitutions, so replace it with $HOME
63
- if string match -q '~/*' -- "$glob_base"
64
- set __tilde_prefix "~"
65
- set glob_base (string replace -r '^~' "$HOME" -- "$glob_base")
66
- else if string match -q '~' -- "$glob_base"
67
- set __tilde_prefix "~"
68
- set glob_base "$HOME/"
115
+ # Expand tilde prefix for globbing — fish does not expand ~
116
+ # inside variable substitutions, so replace it with $HOME. Like
117
+ # fish itself, keep a quoted or escaped tilde in the word literal.
118
+ if test $__from_pattern -eq 1; or string match -q '~*' -- "$__raw_current"
119
+ if string match -q '~/*' -- "$glob_base"
120
+ set __tilde_prefix "~"
121
+ set glob_base (string replace -r '^~' "$HOME" -- "$glob_base")
122
+ else if string match -q '~' -- "$glob_base"
123
+ set __tilde_prefix "~"
124
+ set glob_base "$HOME/"
125
+ end
69
126
  end
70
127
 
71
128
  # If the glob base is a directory without a trailing slash,
@@ -75,54 +132,82 @@ function __drfed_server_complete
75
132
  end
76
133
 
77
134
  # Pre-expand file candidates. When the glob base came from
78
- # the program's pattern and contains * or ?, use it as the
79
- # complete glob expression. Otherwise append * as a prefix.
135
+ # the program's pattern and its basename contains * or ?, use
136
+ # it as the complete glob expression. Otherwise append * as a
137
+ # prefix, so a literal ? in a directory name such as What?/
138
+ # still lists that directory. A pattern equal to the current
139
+ # word is the typed text echoed back (as path() does), so its
140
+ # ? and * are literal characters, not wildcards.
80
141
  # Note: [ is NOT treated as a glob because it commonly
81
142
  # appears in literal filenames like [draft] or foo[1].txt.
82
143
  set -l __has_glob 0
83
144
  if test $__from_pattern -eq 1
84
- and string match -q '*[*?]*' -- "$glob_base"
145
+ and string match -qr '[*?][^/]*$' -- "$glob_base"
146
+ and test "$pattern" != "$current"
85
147
  set __has_glob 1
86
148
  end
87
149
  set -l __candidates
88
150
  if test $__has_glob -eq 1
89
151
  # Safe glob expansion without eval: split the pattern into
90
- # directory and filter parts, list the directory, then use
91
- # string match for wildcard filtering
92
- set -l __glob_dir (string replace -r '/[^/]*$' '' -- "$glob_base")
152
+ # a directory prefix and a basename filter, list the
153
+ # directory, then match basenames against a regex built
154
+ # from the filter. The prefix keeps one empty element for
155
+ # bare patterns so that $__glob_prefix* still expands.
156
+ set -l __glob_prefix ""
157
+ if string match -q '*/*' -- "$glob_base"
158
+ set __glob_prefix (string replace -r '[^/]*$' '' -- "$glob_base")
159
+ end
93
160
  set -l __glob_filter (string replace -r '.*/' '' -- "$glob_base")
94
- if test -z "$__glob_dir"; or test "$__glob_dir" = "$glob_base"
95
- set __glob_dir "."
161
+ # Translate the filter into an anchored regex: * and ? are
162
+ # wildcards and every other character is literal. Fish's
163
+ # own wildcards cannot be used here because ? is literal
164
+ # when the qmark-noglob feature is enabled (fish 4 default).
165
+ set -l __glob_regex '^'
166
+ for __ch in (string split '' -- "$__glob_filter")
167
+ if test "$__ch" = '*'
168
+ set __glob_regex "$__glob_regex.*"
169
+ else if test "$__ch" = '?'
170
+ set __glob_regex "$__glob_regex."
171
+ else
172
+ set __glob_regex "$__glob_regex"(string escape --style=regex -- "$__ch")
173
+ end
96
174
  end
175
+ set __glob_regex "$__glob_regex"'$'
97
176
  # Match files by the glob filter. Fish's * does not match
98
- # dotfiles, so also scan .* when the filter targets them.
99
- for __item in $__glob_dir/*
177
+ # dotfiles, so also scan .* when the filter targets them or
178
+ # hidden files are requested.
179
+ set -l __entries $__glob_prefix*
180
+ if test "$hidden" = "1"; or string match -q '.*' -- "$__glob_filter"
181
+ set -a __entries $__glob_prefix.*
182
+ end
183
+ for __item in $__entries
100
184
  if test -e "$__item"
101
- set -l __bn (basename "$__item")
102
- if string match -q "$__glob_filter" -- "$__bn"
103
- set -a __candidates "$__item"
185
+ set -l __bn (string replace -r '.*/' '' -- "$__item")
186
+ if contains -- "$__bn" . ..
187
+ continue
104
188
  end
105
- end
106
- end
107
- if string match -q '.*' -- "$__glob_filter"
108
- for __item in $__glob_dir/.*
109
- if test -e "$__item"
110
- set -l __bn (basename "$__item")
111
- if test "$__bn" = "." -o "$__bn" = ".."
112
- continue
113
- end
114
- if string match -q "$__glob_filter" -- "$__bn"
115
- set -a __candidates "$__item"
116
- end
189
+ if string match -qr -- "$__glob_regex" "$__bn"
190
+ set -a __candidates "$__item"
117
191
  end
118
192
  end
119
193
  end
120
194
  # For file/any modes, also include directories for navigation.
121
195
  # Skip for directory mode so the pattern filter is respected.
196
+ # Directories the filter already matched are not repeated.
122
197
  if test "$type" != "directory"
123
- for __item in $__glob_dir/*/
198
+ set -l __nav_dirs $__glob_prefix*/
199
+ if test "$hidden" = "1"
200
+ set -a __nav_dirs $__glob_prefix.*/
201
+ end
202
+ for __item in $__nav_dirs
203
+ set __item (string replace -r '/$' '' -- "$__item")
204
+ set -l __bn (string replace -r '.*/' '' -- "$__item")
205
+ if contains -- "$__bn" . ..
206
+ continue
207
+ end
124
208
  if test -d "$__item"
125
- set -a __candidates (string replace -r '/$' '' -- "$__item")
209
+ and not string match -qr -- "$__glob_regex" "$__bn"
210
+ set -a __candidates "$__item"
126
211
  end
127
212
  end
128
213
  end
@@ -225,7 +310,7 @@ function __drfed_server_complete
225
310
  if test "$hidden" != "1" -a (string sub -l 1 -- $__glob_basename) != "."
226
311
  set -l filtered
227
312
  for item in $items
228
- set -l basename (basename $item)
313
+ set -l basename (basename -- "$item")
229
314
  if not string match -q '.*' -- $basename
230
315
  set -a filtered $item
231
316
  end
@@ -242,10 +327,13 @@ function __drfed_server_complete
242
327
  set items $restored
243
328
  end
244
329
 
245
- # Output file completions
330
+ # Output file completions. Use printf rather than echo, which
331
+ # would take filenames like -n or -e as its own options.
246
332
  for item in $items
247
- echo $item
333
+ printf '%s\n' "$insertion_prefix$item"
248
334
  end
335
+ set current "$saved_current"
336
+ set __raw_current "$saved_raw_current"
249
337
  else
250
338
  # Regular literal completion - split by tab
251
339
  set -l parts (string split \t -- $line)
@@ -260,5 +348,5 @@ function __drfed_server_complete
260
348
  end
261
349
  end
262
350
 
263
- complete -c drfed-server -f -a '(__drfed_server_complete)'
351
+ complete -c drfed-server -f -a '(__drfed-server_complete)'
264
352
 
@@ -1,8 +1,31 @@
1
1
 
2
- function __drfed_web_complete
2
+ function __drfed-web_complete
3
3
  set -l tokens (commandline -poc)
4
4
  set -l current (commandline -ct)
5
5
 
6
+ # commandline -poc decodes previous tokens, but commandline -ct returns
7
+ # the current token as typed. Decode its quotes and escapes as well.
8
+ # Keep the token as typed if decoding fails or yields a newline or tab,
9
+ # which completion output cannot carry.
10
+ set -l __raw_current "$current"
11
+ set -l __decoded (string unescape -- "$current")
12
+ or begin
13
+ # string unescape rejects an unfinished trailing backslash. fish
14
+ # keeps it literally inside single quotes, which also keep a " as
15
+ # is, and otherwise waits for the character it escapes.
16
+ set -l __prefix (string replace -r '\\\\$' '' -- "$current")
17
+ set -l __probe (string unescape -- "$__prefix\"")
18
+ set -l __plain (string unescape -- "$__prefix")
19
+ if test "$__probe" = "$__plain\""
20
+ set __decoded (string unescape -- "$current\\")
21
+ else
22
+ set __decoded (string unescape -- "$__prefix")
23
+ end
24
+ end
25
+ and test (count $__decoded) -eq 1
26
+ and not string match -qr '\t' -- "$__decoded"
27
+ and set current "$__decoded"
28
+
6
29
  # Extract previous arguments (skip the command name)
7
30
  set -l prev
8
31
  set -l count (count $tokens)
@@ -15,7 +38,12 @@ function __drfed_web_complete
15
38
 
16
39
  # Process each line of output
17
40
  for line in $output
18
- if string match -q '__FILE__:*' -- $line
41
+ set -l literal 0
42
+ if string match -q '__LITERAL__:*' -- $line
43
+ set line (string sub -s 13 -- $line)
44
+ set literal 1
45
+ end
46
+ if test $literal -eq 0; and string match -q '__FILE__:*' -- $line
19
47
  # Parse file completion directive: __FILE__:type:extensions:pattern:hidden
20
48
  set -l directive (string split \t -- $line)[1]
21
49
  set -l parts (string split ':' -- $directive)
@@ -23,6 +51,34 @@ function __drfed_web_complete
23
51
  set -l extensions $parts[3]
24
52
  set -l pattern (string replace -a '%25' '%' -- (string replace -a '%3A' ':' -- $parts[4]))
25
53
  set -l hidden $parts[5]
54
+ set -l insertion_prefix ""
55
+ if test (count $parts) -ge 6
56
+ set insertion_prefix (string replace -a '%25' '%' -- (string replace -a '%3A' ':' -- $parts[6]))
57
+ end
58
+ set -l saved_current "$current"
59
+ set -l saved_raw_current "$__raw_current"
60
+ set -l prefix_length (string length -- "$insertion_prefix")
61
+ if test $prefix_length -gt 0
62
+ and test (string sub -l $prefix_length -- "$pattern") = "$insertion_prefix"
63
+ and test (string sub -l $prefix_length -- "$current") = "$insertion_prefix"
64
+ set -l start (math $prefix_length + 1)
65
+ set pattern (string sub -s $start -- "$pattern")
66
+ set current (string sub -s $start -- "$current")
67
+ # Keep the raw word aligned so an unquoted key is not mistaken
68
+ # for quoting when comparing it with the decoded value.
69
+ if test (string sub -l $prefix_length -- "$__raw_current") = "$insertion_prefix"
70
+ set __raw_current (string sub -s $start -- "$__raw_current")
71
+ end
72
+ else
73
+ set insertion_prefix ""
74
+ end
75
+
76
+ # path() echoes the current word as its pattern. When that word
77
+ # was quoted or escaped, treat the echo as the typed word rather
78
+ # than as a pattern from the program.
79
+ if test "$current" != "$__raw_current"; and test "$pattern" = "$current"
80
+ set pattern ""
81
+ end
26
82
 
27
83
  # When a pattern is specified, use it as the glob base instead
28
84
  # of the current word. If the user has already typed beyond the
@@ -35,15 +91,13 @@ function __drfed_web_complete
35
91
  # Normalize leading ./ so that ./src/ma matches pattern src/
36
92
  set -l __norm_current (string replace -r '^\./' '' -- "$current")
37
93
  set -l __norm_pattern (string replace -r '^\./' '' -- "$pattern")
38
- # For wildcard patterns, compare only the directory prefix
94
+ # For wildcard patterns, compare only the directory prefix.
95
+ # Use a regex: fish wildcards have no character classes.
96
+ # Only the basename can hold wildcards; a ? or * in a
97
+ # directory name such as What?/ is literal.
39
98
  set -l __compare_pattern "$__norm_pattern"
40
- if string match -q '*[*?]*' -- "$__compare_pattern"
41
- set __compare_pattern (string replace -r '[*?].*' '' -- "$__compare_pattern")
42
- if string match -q '*/*' -- "$__compare_pattern"
43
- set __compare_pattern (string replace -r '/[^/]*$' '/' -- "$__compare_pattern")
44
- else
45
- set __compare_pattern ""
46
- end
99
+ if string match -qr '[*?][^/]*$' -- "$__compare_pattern"
100
+ set __compare_pattern (string replace -r '[^/]*$' '' -- "$__compare_pattern")
47
101
  end
48
102
  set -l __cp_len (string length -- "$__compare_pattern")
49
103
  set -l __nc_len (string length -- "$__norm_current")
@@ -58,14 +112,17 @@ function __drfed_web_complete
58
112
  end
59
113
  end
60
114
 
61
- # Expand tilde prefix for globbing—fish does not expand ~
62
- # inside variable substitutions, so replace it with $HOME
63
- if string match -q '~/*' -- "$glob_base"
64
- set __tilde_prefix "~"
65
- set glob_base (string replace -r '^~' "$HOME" -- "$glob_base")
66
- else if string match -q '~' -- "$glob_base"
67
- set __tilde_prefix "~"
68
- set glob_base "$HOME/"
115
+ # Expand tilde prefix for globbing — fish does not expand ~
116
+ # inside variable substitutions, so replace it with $HOME. Like
117
+ # fish itself, keep a quoted or escaped tilde in the word literal.
118
+ if test $__from_pattern -eq 1; or string match -q '~*' -- "$__raw_current"
119
+ if string match -q '~/*' -- "$glob_base"
120
+ set __tilde_prefix "~"
121
+ set glob_base (string replace -r '^~' "$HOME" -- "$glob_base")
122
+ else if string match -q '~' -- "$glob_base"
123
+ set __tilde_prefix "~"
124
+ set glob_base "$HOME/"
125
+ end
69
126
  end
70
127
 
71
128
  # If the glob base is a directory without a trailing slash,
@@ -75,54 +132,82 @@ function __drfed_web_complete
75
132
  end
76
133
 
77
134
  # Pre-expand file candidates. When the glob base came from
78
- # the program's pattern and contains * or ?, use it as the
79
- # complete glob expression. Otherwise append * as a prefix.
135
+ # the program's pattern and its basename contains * or ?, use
136
+ # it as the complete glob expression. Otherwise append * as a
137
+ # prefix, so a literal ? in a directory name such as What?/
138
+ # still lists that directory. A pattern equal to the current
139
+ # word is the typed text echoed back (as path() does), so its
140
+ # ? and * are literal characters, not wildcards.
80
141
  # Note: [ is NOT treated as a glob because it commonly
81
142
  # appears in literal filenames like [draft] or foo[1].txt.
82
143
  set -l __has_glob 0
83
144
  if test $__from_pattern -eq 1
84
- and string match -q '*[*?]*' -- "$glob_base"
145
+ and string match -qr '[*?][^/]*$' -- "$glob_base"
146
+ and test "$pattern" != "$current"
85
147
  set __has_glob 1
86
148
  end
87
149
  set -l __candidates
88
150
  if test $__has_glob -eq 1
89
151
  # Safe glob expansion without eval: split the pattern into
90
- # directory and filter parts, list the directory, then use
91
- # string match for wildcard filtering
92
- set -l __glob_dir (string replace -r '/[^/]*$' '' -- "$glob_base")
152
+ # a directory prefix and a basename filter, list the
153
+ # directory, then match basenames against a regex built
154
+ # from the filter. The prefix keeps one empty element for
155
+ # bare patterns so that $__glob_prefix* still expands.
156
+ set -l __glob_prefix ""
157
+ if string match -q '*/*' -- "$glob_base"
158
+ set __glob_prefix (string replace -r '[^/]*$' '' -- "$glob_base")
159
+ end
93
160
  set -l __glob_filter (string replace -r '.*/' '' -- "$glob_base")
94
- if test -z "$__glob_dir"; or test "$__glob_dir" = "$glob_base"
95
- set __glob_dir "."
161
+ # Translate the filter into an anchored regex: * and ? are
162
+ # wildcards and every other character is literal. Fish's
163
+ # own wildcards cannot be used here because ? is literal
164
+ # when the qmark-noglob feature is enabled (fish 4 default).
165
+ set -l __glob_regex '^'
166
+ for __ch in (string split '' -- "$__glob_filter")
167
+ if test "$__ch" = '*'
168
+ set __glob_regex "$__glob_regex.*"
169
+ else if test "$__ch" = '?'
170
+ set __glob_regex "$__glob_regex."
171
+ else
172
+ set __glob_regex "$__glob_regex"(string escape --style=regex -- "$__ch")
173
+ end
96
174
  end
175
+ set __glob_regex "$__glob_regex"'$'
97
176
  # Match files by the glob filter. Fish's * does not match
98
- # dotfiles, so also scan .* when the filter targets them.
99
- for __item in $__glob_dir/*
177
+ # dotfiles, so also scan .* when the filter targets them or
178
+ # hidden files are requested.
179
+ set -l __entries $__glob_prefix*
180
+ if test "$hidden" = "1"; or string match -q '.*' -- "$__glob_filter"
181
+ set -a __entries $__glob_prefix.*
182
+ end
183
+ for __item in $__entries
100
184
  if test -e "$__item"
101
- set -l __bn (basename "$__item")
102
- if string match -q "$__glob_filter" -- "$__bn"
103
- set -a __candidates "$__item"
185
+ set -l __bn (string replace -r '.*/' '' -- "$__item")
186
+ if contains -- "$__bn" . ..
187
+ continue
104
188
  end
105
- end
106
- end
107
- if string match -q '.*' -- "$__glob_filter"
108
- for __item in $__glob_dir/.*
109
- if test -e "$__item"
110
- set -l __bn (basename "$__item")
111
- if test "$__bn" = "." -o "$__bn" = ".."
112
- continue
113
- end
114
- if string match -q "$__glob_filter" -- "$__bn"
115
- set -a __candidates "$__item"
116
- end
189
+ if string match -qr -- "$__glob_regex" "$__bn"
190
+ set -a __candidates "$__item"
117
191
  end
118
192
  end
119
193
  end
120
194
  # For file/any modes, also include directories for navigation.
121
195
  # Skip for directory mode so the pattern filter is respected.
196
+ # Directories the filter already matched are not repeated.
122
197
  if test "$type" != "directory"
123
- for __item in $__glob_dir/*/
198
+ set -l __nav_dirs $__glob_prefix*/
199
+ if test "$hidden" = "1"
200
+ set -a __nav_dirs $__glob_prefix.*/
201
+ end
202
+ for __item in $__nav_dirs
203
+ set __item (string replace -r '/$' '' -- "$__item")
204
+ set -l __bn (string replace -r '.*/' '' -- "$__item")
205
+ if contains -- "$__bn" . ..
206
+ continue
207
+ end
124
208
  if test -d "$__item"
125
- set -a __candidates (string replace -r '/$' '' -- "$__item")
209
+ and not string match -qr -- "$__glob_regex" "$__bn"
210
+ set -a __candidates "$__item"
126
211
  end
127
212
  end
128
213
  end
@@ -225,7 +310,7 @@ function __drfed_web_complete
225
310
  if test "$hidden" != "1" -a (string sub -l 1 -- $__glob_basename) != "."
226
311
  set -l filtered
227
312
  for item in $items
228
- set -l basename (basename $item)
313
+ set -l basename (basename -- "$item")
229
314
  if not string match -q '.*' -- $basename
230
315
  set -a filtered $item
231
316
  end
@@ -242,10 +327,13 @@ function __drfed_web_complete
242
327
  set items $restored
243
328
  end
244
329
 
245
- # Output file completions
330
+ # Output file completions. Use printf rather than echo, which
331
+ # would take filenames like -n or -e as its own options.
246
332
  for item in $items
247
- echo $item
333
+ printf '%s\n' "$insertion_prefix$item"
248
334
  end
335
+ set current "$saved_current"
336
+ set __raw_current "$saved_raw_current"
249
337
  else
250
338
  # Regular literal completion - split by tab
251
339
  set -l parts (string split \t -- $line)
@@ -260,5 +348,5 @@ function __drfed_web_complete
260
348
  end
261
349
  end
262
350
 
263
- complete -c drfed-web -f -a '(__drfed_web_complete)'
351
+ complete -c drfed-web -f -a '(__drfed-web_complete)'
264
352