@drfed/drfed 0.2.0-dev.567 → 0.2.0-dev.608

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-91KEch3P.mjs +6 -0
  41. package/dist/package-91KEch3P.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 +15 -15
  45. package/dist/package-CaLSz3rX.mjs +0 -6
  46. package/dist/package-CaLSz3rX.mjs.map +0 -1
@@ -1,14 +1,297 @@
1
1
 
2
2
  function _drfed-server () {
3
3
  COMPREPLY=()
4
- local current="${COMP_WORDS[COMP_CWORD]}"
4
+ local __raw_current="${COMP_WORDS[COMP_CWORD]}"
5
+ local current="" __quote="" __char __next __index __quote_offset=0
6
+ local __file_mode=0
7
+ if [[ $(type -t compopt) == builtin ]]; then
8
+ compopt +o filenames 2>/dev/null || true
9
+ fi
10
+ # Dequote the shell word without evaluating filename contents. Readline
11
+ # returns escaped words after Tab, and users may start with an open quote.
12
+ for ((__index=0; __index<${#__raw_current}; __index++)); do
13
+ __char="${__raw_current:__index:1}"
14
+ if [[ -z "$__quote" ]]; then
15
+ case "$__char" in
16
+ \\) ((++__index)); current+="${__raw_current:__index:1}" ;;
17
+ \'|\") __quote="$__char"; __quote_offset=${#current} ;;
18
+ *) current+="$__char" ;;
19
+ esac
20
+ elif [[ "$__quote" == "'" ]]; then
21
+ if [[ "$__char" == "'" ]]; then
22
+ __quote=""
23
+ else
24
+ current+="$__char"
25
+ fi
26
+ else
27
+ case "$__char" in
28
+ \") __quote="" ;;
29
+ \\)
30
+ __next="${__raw_current:__index+1:1}"
31
+ case "$__next" in
32
+ \$|\`|\"|\\)
33
+ ((++__index)); current+="$__next" ;;
34
+ *) current+="$__char" ;;
35
+ esac ;;
36
+ *) current+="$__char" ;;
37
+ esac
38
+ fi
39
+ done
40
+ local __tilde_pattern='^(~[a-zA-Z0-9_.+-]*)(/.*)?$'
41
+ local __tilde_glob_pattern='^(~[a-zA-Z0-9_.+-]*)(/.*)?$'
5
42
  local prev=("${COMP_WORDS[@]:1:COMP_CWORD-1}")
6
- while IFS= read -r line; do
7
- if [[ "$line" == __FILE__:* ]]; then
8
- # Parse file completion directive: __FILE__:type:extensions:pattern:hidden
9
- IFS=':' read -r _ type extensions pattern hidden <<< "$line"
43
+ # Bash splits unquoted '=' at its default word breaks. Reassemble only
44
+ # adjacent fragments, including further word breaks inside a joined value,
45
+ # leaving whitespace-separated arguments intact.
46
+ local __plain_current="$current" __remove="" __word __joined=0
47
+ local __raw_joined_current="$__raw_current"
48
+ local -a __raw_offsets=() __raw_quotes=()
49
+ if [[ ${COMP_LINE+x} ]]; then
50
+ local -a __words=()
51
+ local __rest="$COMP_LINE" __previous="" __space __valid=1 __i __j=0
52
+ local __shell_quote="" __shell_escape=0 __boundary=0 __previous_boundary=0 __scan __symbol __shell_dollar=0
53
+ # Reconstruct the prefix at the cursor, leaving any suffix to Readline.
54
+ if [[ ${COMP_POINT+x} ]]; then
55
+ __rest="${COMP_LINE:0:COMP_POINT}"
56
+ fi
57
+ for ((__i=0; __i<=COMP_CWORD; __i++)); do
58
+ __word="${COMP_WORDS[__i]}"
59
+ __space=0
60
+ while [[ "$__rest" == [[:space:]]* ]]; do
61
+ __space=1
62
+ __rest="${__rest:1}"
63
+ done
64
+ if (( __i == COMP_CWORD && ${#__rest} < ${#__word} )); then
65
+ __word="${__word:0:${#__rest}}"
66
+ fi
67
+ if [[ "${__rest:0:${#__word}}" != "$__word" ]]; then
68
+ __valid=0
69
+ break
70
+ fi
71
+ # Quoted or escaped operators belong to words; bare operators separate
72
+ # shell syntax even when no whitespace surrounds a redirection.
73
+ __boundary=0
74
+ for ((__scan=0; __scan<${#__word}; __scan++)); do
75
+ __symbol="${__word:__scan:1}"
76
+ if (( __shell_escape )); then
77
+ __shell_escape=0
78
+ elif [[ "$__shell_quote" == ansi ]]; then
79
+ if [[ "$__symbol" == '\' ]]; then __shell_escape=1
80
+ elif [[ "$__symbol" == "'" ]]; then __shell_quote=""; fi
81
+ elif [[ "$__shell_quote" == "'" ]]; then
82
+ [[ "$__symbol" == "'" ]] && __shell_quote=""
83
+ elif [[ "$__symbol" == '\' ]]; then
84
+ __shell_escape=1
85
+ elif [[ -n "$__shell_quote" ]]; then
86
+ [[ "$__symbol" == "$__shell_quote" ]] && __shell_quote=""
87
+ else
88
+ case "$__symbol" in
89
+ "'")
90
+ if (( __shell_dollar )); then __shell_quote=ansi
91
+ else __shell_quote="'"; fi ;;
92
+ '"') __shell_quote='"' ;;
93
+ '$') __shell_dollar=1 ;;
94
+ '>'|'<'|'|'|'&'|';'|'('|')') __boundary=1 ;;
95
+ esac
96
+ fi
97
+ [[ "$__symbol" == '$' && -z "$__shell_quote" ]] || __shell_dollar=0
98
+ done
99
+ if (( __i > 1 && !__space && !__boundary && !__previous_boundary )) &&
100
+ { [[ -n "$__word" && -z "${__word//=/}" ]] ||
101
+ [[ -n "$__previous" && -z "${__previous//=/}" ]] ||
102
+ [[ "${__words[__j-1]}" == [-/+]* ]] ||
103
+ [[ "$__word" == =* && "${__words[__j-1]}" == [-/+]* ]]; }; then
104
+ __words[__j-1]+="$__word"
105
+ else
106
+ __words[__j]="$__word"
107
+ ((++__j))
108
+ fi
109
+ __rest="${__rest:${#__word}}"
110
+ __previous="$__word"
111
+ __previous_boundary=$__boundary
112
+ done
113
+ if (( __valid )); then
114
+ current="${__words[__j-1]}"
115
+ __raw_joined_current="$current"
116
+ prev=("${__words[@]:1:__j-2}")
117
+ # Bash passes the fragment Readline will replace as the second argument,
118
+ # which is empty when the cursor follows a word-break character.
119
+ if [[ ${2+x} ]]; then
120
+ __remove="${current:0:${#current}-${#2}}"
121
+ elif [[ -n "$__raw_current" && -z "${__raw_current//=/}" ]]; then
122
+ __remove="$current"
123
+ else
124
+ __remove="${current:0:${#current}-${#__raw_current}}"
125
+ fi
126
+ # Decode joined shell words without evaluating substitutions. Keep quote
127
+ # state across the reassembled fragments and decode the preserved prefix
128
+ # separately so trimming uses the same representation as suggestions.
129
+ __words[__j]="$__remove"
130
+ local __decoded __decoded_option=0 __before_quote __join_quote __char __next __k __ansi __part __digits __code __join_quote_offset
131
+ for ((__i=1; __i<=__j; __i++)); do
132
+ __word="${__words[__i]}"
133
+ __decoded=""; __join_quote=""; __join_quote_offset=0
134
+ for ((__k=0; __k<${#__word}; __k++)); do
135
+ __char="${__word:__k:1}"
136
+ __before_quote="$__join_quote"
137
+ if [[ -z "$__join_quote" ]]; then
138
+ case "$__char" in
139
+ '\') ((++__k)); __decoded+="${__word:__k:1}" ;;
140
+ '$')
141
+ if [[ "${__word:__k+1:1}" == "'" ]]; then
142
+ __join_quote=ansi; __join_quote_offset=${#__decoded}; __ansi=""; ((++__k))
143
+ elif [[ "${__word:__k+1:1}" == '"' ]]; then
144
+ __join_quote='"'; __join_quote_offset=${#__decoded}; ((++__k))
145
+ else __decoded+="$__char"; fi ;;
146
+ "'"|'"') __join_quote="$__char"; __join_quote_offset=${#__decoded} ;;
147
+ *) __decoded+="$__char" ;;
148
+ esac
149
+ elif [[ "$__join_quote" == ansi ]]; then
150
+ if [[ "$__char" == "'" ]]; then
151
+ printf -v __part '%b' "$__ansi"
152
+ __decoded+="$__part"; __join_quote=""
153
+ elif [[ "$__char" == '\' ]]; then
154
+ ((++__k)); __next="${__word:__k:1}"
155
+ case "$__next" in
156
+ [0-7])
157
+ __digits="$__next"
158
+ while (( ${#__digits} < 3 )) && [[ "${__word:__k+1:1}" == [0-7] ]]; do
159
+ ((++__k)); __digits+="${__word:__k:1}"
160
+ done
161
+ __ansi+='\0'"$__digits" ;;
162
+ c)
163
+ __next="${__word:__k+1:1}"
164
+ if [[ -n "$__next" && "$__next" != "'" ]]; then
165
+ ((++__k)); printf -v __code '%d' "'$__next"
166
+ if [[ "$__next" == '?' ]]; then __code=127
167
+ else __code=$((__code & 31)); fi
168
+ printf -v __part '\\%03o' "$__code"
169
+ __ansi+="$__part"
170
+ else __ansi+='\\c'; fi ;;
171
+ "'"|'"'|'?') __ansi+="$__next" ;;
172
+ *) __ansi+='\'"$__next" ;;
173
+ esac
174
+ else __ansi+="$__char"; fi
175
+ elif [[ "$__join_quote" == "'" ]]; then
176
+ if [[ "$__char" == "'" ]]; then __join_quote=""
177
+ else __decoded+="$__char"; fi
178
+ else
179
+ case "$__char" in
180
+ '"') __join_quote="" ;;
181
+ '\')
182
+ __next="${__word:__k+1:1}"
183
+ case "$__next" in
184
+ '$'|'`'|'"'|'\') ((++__k)); __decoded+="$__next" ;;
185
+ *) __decoded+="$__char" ;;
186
+ esac ;;
187
+ *) __decoded+="$__char" ;;
188
+ esac
189
+ fi
190
+ if (( __i == __j - 1 )) &&
191
+ { [[ ! ${__raw_offsets[${#__decoded}]+x} ]] ||
192
+ [[ -n "$__before_quote" && -z "$__join_quote" ]]; }; then
193
+ __raw_offsets[${#__decoded}]=$((__k + 1))
194
+ __raw_quotes[${#__decoded}]="$__join_quote"
195
+ fi
196
+ done
197
+ if [[ "$__join_quote" == ansi ]]; then
198
+ printf -v __part '%b' "$__ansi"
199
+ __decoded+="$__part"
200
+ fi
201
+ # Shell syntax may precede the option prefix. Decide from decoded text,
202
+ # retaining the existing native-file handling for non-option words.
203
+ if [[ "$__decoded" == [-/+]* ]] || (( __i == __j && __decoded_option )); then
204
+ if (( __i == __j - 1 )); then
205
+ __decoded_option=1
206
+ __quote="$__join_quote"
207
+ [[ "$__quote" == ansi ]] && __quote="'"
208
+ __quote_offset=$__join_quote_offset
209
+ fi
210
+ __words[__i]="$__decoded"
211
+ fi
212
+ done
213
+ if [[ "${__words[__j-1]}" == -*=* || "${__words[__j-1]}" == /*:* || "${__words[__j-1]}" != "$__raw_current" ]]; then
214
+ current="${__words[__j-1]}"
215
+ __joined=1
216
+ else
217
+ current="$__plain_current"
218
+ __words[__j]=""
219
+ fi
220
+ prev=("${__words[@]:1:__j-2}")
221
+ __remove="${__words[__j]}"
222
+ fi
223
+ fi
224
+
225
+ # Joined file directives retain the exact option prefix and metadata chosen
226
+ # by the parser; do not infer option boundaries through speculative retries.
227
+ local __protocol_current="$__raw_current"
228
+ (( __joined )) && __protocol_current="$current"
229
+ local -a __lines=() __replies=()
230
+ local line __reply_prefix="" __file_current="$current" __literal=0
231
+ while IFS= read -r line || [[ -n "$line" ]]; do
232
+ [[ -n "$line" ]] && __lines+=("$line")
233
+ done < <(drfed-server 'completion' 'bash' "${prev[@]}" "$__protocol_current" 2>/dev/null)
234
+ for line in "${__lines[@]}"; do
235
+ COMPREPLY=()
236
+ __reply_prefix=""
237
+ __file_current="$current"
238
+ __literal=0
239
+ # Protocol tags are case-sensitive even when nocasematch is enabled.
240
+ if [ "${line:0:12}" = '__LITERAL__:' ]; then
241
+ line="${line#__LITERAL__:}"
242
+ __literal=1
243
+ elif [ "${line:0:16}" = '__JOINED_FILE__:' ]; then
244
+ line="${line#__JOINED_FILE__:}"
245
+ __reply_prefix="${line%%:*}"
246
+ __reply_prefix="${__reply_prefix//%3A/:}"
247
+ __reply_prefix="${__reply_prefix//%25/%}"
248
+ line="__FILE__:${line#*:}"
249
+ __file_current="${current:${#__reply_prefix}}"
250
+ fi
251
+ local __raw_file_current="$__raw_current" __file_quote_offset=$__quote_offset __file_tilde_quoted=0
252
+ if [[ -n "$__reply_prefix" ]]; then
253
+ local __raw_offset="${__raw_offsets[${#__reply_prefix}]:-${#__reply_prefix}}"
254
+ __raw_file_current="${__raw_joined_current:__raw_offset}"
255
+ # Quoting may start before the option name and remain active at the
256
+ # delimiter. Keep that context when deciding whether tilde is literal.
257
+ if [[ -n "${__raw_quotes[${#__reply_prefix}]-}" ]]; then
258
+ __file_tilde_quoted=1
259
+ fi
260
+ if (( __file_quote_offset >= ${#__reply_prefix} )); then
261
+ __file_quote_offset=$((__file_quote_offset - ${#__reply_prefix}))
262
+ fi
263
+ fi
264
+ if [ "$__literal" = 0 ] && [ "${line:0:9}" = '__FILE__:' ]; then
265
+ # Parse file completion directive:
266
+ # __FILE__:type:extensions:pattern:hidden[:insertion_prefix]
267
+ local insertion_prefix="" __key_current="$__file_current"
268
+ IFS=':' read -r _ type extensions pattern hidden insertion_prefix <<< "$line"
10
269
  extensions="${extensions//,\./,}"; extensions="${extensions#.}"
11
270
  pattern="${pattern//%3A/:}"; pattern="${pattern//%25/%}"
271
+ insertion_prefix="${insertion_prefix//%3A/:}"; insertion_prefix="${insertion_prefix//%25/%}"
272
+ local __reply_start=${#COMPREPLY[@]}
273
+
274
+ # Inserted keys are not filesystem paths. Match only the value part,
275
+ # then restore the key once the file candidates have been filtered.
276
+ if [[ -n "$insertion_prefix" ]] &&
277
+ [ "${pattern:0:${#insertion_prefix}}" = "$insertion_prefix" ] &&
278
+ [ "${__file_current:0:${#insertion_prefix}}" = "$insertion_prefix" ]; then
279
+ pattern="${pattern:${#insertion_prefix}}"
280
+ __file_current="${__file_current:${#insertion_prefix}}"
281
+ if [ "${__raw_file_current:0:${#insertion_prefix}}" = "$insertion_prefix" ]; then
282
+ __raw_file_current="${__raw_file_current:${#insertion_prefix}}"
283
+ fi
284
+ else
285
+ insertion_prefix=""
286
+ fi
287
+
288
+ # path() echoes the raw shell word as its pattern. Once dequoted,
289
+ # use the literal current-word prefix instead of the escaped pattern.
290
+ if [[ "$pattern" == "$__raw_file_current" && "$__file_current" != "$__raw_file_current" ]] ||
291
+ { [[ -n "$__reply_prefix" ]] && [ "$pattern" = "$__file_current" ] &&
292
+ { [[ "$pattern" != *[*?]* ]] || [ "$__raw_file_current" != "$__file_current" ]; }; }; then
293
+ pattern=""
294
+ fi
12
295
 
13
296
  # Save and adjust glob/shell options for safe file completion
14
297
  local __dotglob_was_set=0 __failglob_was_set=0 __noglob_was_set=0
@@ -24,12 +307,12 @@ function _drfed-server () {
24
307
  unset GLOBIGNORE
25
308
 
26
309
  # Expand tilde prefix for file globbing
27
- local __glob_current="$current" __tilde_prefix="" __tilde_expanded=""
28
- if [[ "$current" =~ ^(~[a-zA-Z0-9_.+-]*)(/.*)$ ]]; then
310
+ local __glob_current="$__file_current" __tilde_prefix="" __tilde_expanded=""
311
+ if [[ $__file_tilde_quoted == 0 && "$__raw_file_current" == "~"* && "$__file_current" =~ $__tilde_pattern ]]; then
29
312
  __tilde_prefix="${BASH_REMATCH[1]}"
30
313
  eval "__tilde_expanded=$__tilde_prefix" 2>/dev/null || true
31
314
  if [[ -n "$__tilde_expanded" && "$__tilde_expanded" != "$__tilde_prefix" ]]; then
32
- __glob_current="${__tilde_expanded}${current#$__tilde_prefix}"
315
+ __glob_current="${__tilde_expanded}${__file_current#$__tilde_prefix}"
33
316
  else
34
317
  __tilde_prefix=""
35
318
  fi
@@ -40,10 +323,11 @@ function _drfed-server () {
40
323
  # However, if the user has already typed beyond the pattern (e.g.,
41
324
  # pattern="src/" and current="src/ma"), preserve the typed suffix
42
325
  # for incremental filtering.
43
- local __from_pattern=0
326
+ local __from_pattern=0 __filter_pattern=0 __pattern_prefix=""
327
+ local __pattern_tilde_prefix="" __pattern_tilde_expanded=""
44
328
  if [[ -n "$pattern" ]]; then
45
329
  # Normalize leading ./ so that ./src/ma matches pattern src/
46
- local __norm_current="${current#./}"
330
+ local __norm_current="${__file_current#./}"
47
331
  local __norm_pattern="${pattern#./}"
48
332
  # For wildcard patterns, compare only the directory prefix before
49
333
  # any wildcards so that typing src/ma narrows src/*.ts correctly
@@ -52,17 +336,34 @@ function _drfed-server () {
52
336
  __compare_pattern="${__compare_pattern%%[*?]*}"
53
337
  [[ "$__compare_pattern" == */* ]] && __compare_pattern="${__compare_pattern%/*}/" || __compare_pattern=""
54
338
  fi
55
- if [[ ( -n "$__compare_pattern" || -n "$__norm_current" ) && ${#__norm_current} -ge ${#__compare_pattern} && "${__norm_current:0:${#__compare_pattern}}" == "$__compare_pattern" && "$current" != "$pattern" ]]; then
339
+ local __extends_pattern=0
340
+ if [[ ( -n "$__compare_pattern" || -n "$__norm_current" ) && ${#__norm_current} -ge ${#__compare_pattern} && "${__norm_current:0:${#__compare_pattern}}" == "$__compare_pattern" && "$__file_current" != "$pattern" ]]; then
341
+ __extends_pattern=1
342
+ fi
343
+ if (( __extends_pattern )) && [[ "$__norm_pattern" != *[*?]* ]]; then
56
344
  # User has typed beyond or an equivalent form of the pattern
57
345
  true
58
346
  else
347
+ # Wildcards keep their file filter while the typed prefix narrows
348
+ # the resulting paths. Save the expanded prefix before using pattern.
349
+ if [[ "$__norm_pattern" == *[*?]* ]]; then
350
+ __filter_pattern=1
351
+ __pattern_prefix="$__glob_current"
352
+ # An unquoted value equal to its wildcard is a complete search
353
+ # pattern, not a literal filename prefix to filter against.
354
+ if [ "$__file_current" = "$pattern" ] && [ "$__raw_file_current" = "$__file_current" ]; then
355
+ __pattern_prefix=""
356
+ fi
357
+ __pattern_tilde_prefix="$__tilde_prefix"
358
+ __pattern_tilde_expanded="$__tilde_expanded"
359
+ fi
59
360
  __from_pattern=1
60
361
  # Reset tilde state from the current-word expansion so that a
61
362
  # non-tilde pattern is not rewritten through stale tilde state
62
363
  __tilde_prefix=""
63
364
  __tilde_expanded=""
64
365
  __glob_current="$pattern"
65
- if [[ "$pattern" =~ ^(~[a-zA-Z0-9_.+-]*)(/.*)?$ ]]; then
366
+ if [[ "$pattern" =~ $__tilde_glob_pattern ]]; then
66
367
  __tilde_prefix="${BASH_REMATCH[1]}"
67
368
  eval "__tilde_expanded=$__tilde_prefix" 2>/dev/null || true
68
369
  if [[ -n "$__tilde_expanded" && "$__tilde_expanded" != "$__tilde_prefix" ]]; then
@@ -84,36 +385,93 @@ function _drfed-server () {
84
385
  # This runs after tilde expansion so that paths like ~/.config/ are
85
386
  # checked against the expanded path, not the literal ~ string.
86
387
  local __inside_hidden_path=0
87
- case "/${__glob_current%/}/" in
88
- */.[!.]*/*|*/..?*/*) __inside_hidden_path=1 ;;
89
- esac
388
+ local __hidden_directory_pattern='/[.]([^./][^/]*|[.][^/]+)/'
389
+ if [[ "/${__glob_current%/}/" =~ $__hidden_directory_pattern ||
390
+ "/${__pattern_prefix%/}/" =~ $__hidden_directory_pattern ]]; then
391
+ __inside_hidden_path=1
392
+ fi
90
393
  # Also check if the current prefix explicitly targets hidden entries
91
394
  # (e.g., user typed "." or ".e" to complete .env)
92
395
  local __prefix_targets_hidden=0
93
396
  local __prefix_base="${__glob_current##*/}"
397
+ if [[ -n "$__pattern_prefix" ]]; then __prefix_base="${__pattern_prefix##*/}"; fi
94
398
  [[ "$__prefix_base" == .* ]] && __prefix_targets_hidden=1
95
399
  if [[ "$hidden" == "1" || "$__inside_hidden_path" == "1" || "$__prefix_targets_hidden" == "1" ]]; then shopt -s dotglob; fi
96
400
 
97
401
  # Pre-expand file candidates. When the glob base came from the
98
402
  # program's pattern and contains wildcard characters (* or ?),
99
- # use it as-is via compgen -G (safe—no command substitution).
403
+ # expand it as data with shell globbing. Empty IFS avoids splitting paths;
404
+ # NUL records preserve spaces and newlines without requiring mapfile.
405
+ # Shell expansion respects dotglob on older Bash versions as well.
100
406
  # Otherwise append * to treat it as a prefix.
101
- # Note: [ is NOT treated as a glob indicator because it commonly
102
- # appears in literal filenames like [draft] or foo[1].txt.
407
+ # Only * and ? are wildcard syntax; escape brackets, backslashes, and
408
+ # extended-glob operators so other pattern characters stay literal.
103
409
  local -a __candidates=()
104
410
  if [[ "$__from_pattern" == "1" && "$__glob_current" == *[*?]* ]]; then
105
- mapfile -t __candidates < <(compgen -G "$__glob_current" 2>/dev/null)
411
+ local __pathname_glob="" __glob_char __glob_index
412
+ for ((__glob_index=0; __glob_index<${#__glob_current}; __glob_index++)); do
413
+ __glob_char="${__glob_current:__glob_index:1}"
414
+ case "$__glob_char" in
415
+ '['|']'|'\'|'('|')'|'|'|'+'|'@'|'!')
416
+ __pathname_glob+="\\$__glob_char" ;;
417
+ *) __pathname_glob+="$__glob_char" ;;
418
+ esac
419
+ done
420
+ [[ "$type" == "directory" ]] && __pathname_glob="${__pathname_glob%/}"
421
+ local __glob_dir="${__pathname_glob%/*}"
422
+ [[ "$__glob_dir" == "$__pathname_glob" ]] && __glob_dir="."
423
+ [[ -z "$__glob_dir" ]] && __glob_dir="/"
424
+ local __navigation_dir="" __basename_glob="${__pathname_glob##*/}"
425
+ # Once an offered directory is entered, keep the basename filter but
426
+ # enumerate there. Only descendants of matching pattern bases qualify.
427
+ if [[ "$__pattern_prefix" == */* ]]; then
428
+ local __typed_dir="${__pattern_prefix%/*}" __base_dir __norm_base __norm_dir
429
+ # Resolve directory ancestry in subshells, preserving the typed spelling
430
+ # for insertion. The trailing slash also preserves newline-ending names.
431
+ if __norm_dir=$(CDPATH= builtin cd -P -- "$__typed_dir" >/dev/null 2>&1 && printf '%s/' "${PWD%/}"); then
432
+ while IFS= read -r -d '' __base_dir; do
433
+ [[ -d "$__base_dir" ]] || continue
434
+ __norm_base=$(CDPATH= builtin cd -P -- "$__base_dir" >/dev/null 2>&1 && printf '%s/' "${PWD%/}") || continue
435
+ if [ "${__norm_dir:0:${#__norm_base}}" = "$__norm_base" ]; then
436
+ __navigation_dir="$__typed_dir"
437
+ break
438
+ fi
439
+ done < <(IFS=; printf '%s\0' $__glob_dir)
440
+ fi
441
+ fi
442
+ local __candidate
443
+ while IFS= read -r -d '' __candidate; do
444
+ if [[ -e "$__candidate" || -L "$__candidate" ]]; then
445
+ [[ -d "$__candidate" ]] && __candidate="${__candidate%/}"
446
+ __candidates+=("$__candidate")
447
+ fi
448
+ done < <(
449
+ IFS=
450
+ if [[ -n "$__navigation_dir" ]]; then
451
+ printf '%s\0' "$__navigation_dir"/$__basename_glob
452
+ else
453
+ printf '%s\0' $__pathname_glob
454
+ fi
455
+ )
106
456
  # For file/any modes, also include directories from the base
107
457
  # directory for navigation even when the glob itself does not
108
458
  # match directory names. Skip this for directory mode so that
109
459
  # the pattern's basename filter is respected.
110
460
  if [[ "$type" != "directory" ]]; then
111
- local __glob_dir="${__glob_current%/*}"
112
- [[ "$__glob_dir" == "$__glob_current" ]] && __glob_dir="."
113
461
  local __d
114
- for __d in "$__glob_dir"/*/; do
115
- [[ -d "$__d" ]] && __candidates+=("${__d%/}")
116
- done
462
+ local __directory_pattern="${__glob_dir%/}/*/"
463
+ while IFS= read -r -d '' __d; do
464
+ [[ -d "$__d" ]] || continue
465
+ __d="${__d%/}"
466
+ __candidates+=("$__d")
467
+ done < <(
468
+ IFS=
469
+ if [[ -n "$__navigation_dir" ]]; then
470
+ printf '%s\0' "$__navigation_dir"/*/
471
+ else
472
+ printf '%s\0' $__directory_pattern
473
+ fi
474
+ )
117
475
  fi
118
476
  else
119
477
  __candidates=("$__glob_current"*)
@@ -124,6 +482,26 @@ function _drfed-server () {
124
482
  fi
125
483
  fi
126
484
 
485
+ if (( __filter_pattern )); then
486
+ local __nocasematch_was_set=0
487
+ shopt -q nocasematch && __nocasematch_was_set=1
488
+ if shopt -q nocaseglob; then shopt -s nocasematch; else shopt -u nocasematch; fi
489
+ local -a __filtered_candidates=()
490
+ for __candidate in "${__candidates[@]}"; do
491
+ if [[ "$__candidate" == "$__pattern_prefix"* ||
492
+ "${__candidate#./}" == "${__pattern_prefix#./}"* ]]; then
493
+ if [[ "$__pattern_prefix" == ./* && "$__candidate" != ./* ]]; then
494
+ __candidate="./$__candidate"
495
+ elif [[ "$__pattern_prefix" != ./* && "$__pattern_prefix" != . ]]; then
496
+ __candidate="${__candidate#./}"
497
+ fi
498
+ __filtered_candidates+=("$__candidate")
499
+ fi
500
+ done
501
+ if (( __nocasematch_was_set )); then shopt -s nocasematch; else shopt -u nocasematch; fi
502
+ __candidates=("${__filtered_candidates[@]}")
503
+ fi
504
+
127
505
  # Generate file completions based on type
128
506
  case "$type" in
129
507
  file)
@@ -131,10 +509,11 @@ function _drfed-server () {
131
509
  if [[ -n "$extensions" ]]; then
132
510
  # Files with extension filtering + directories
133
511
  local ext_pattern="${extensions//,/|}"
512
+ ext_pattern='\.('"$ext_pattern"')$'
134
513
  for item in "${__candidates[@]}"; do
135
514
  if [[ -d "$item" ]]; then
136
515
  COMPREPLY+=("$item/")
137
- elif [[ -f "$item" && "$item" =~ \.($ext_pattern)$ ]]; then
516
+ elif [[ -f "$item" && "$item" =~ $ext_pattern ]]; then
138
517
  COMPREPLY+=("$item")
139
518
  fi
140
519
  done
@@ -161,10 +540,11 @@ function _drfed-server () {
161
540
  # Files with extension filtering + directories
162
541
  # Files with extension filtering
163
542
  local ext_pattern="${extensions//,/|}"
543
+ ext_pattern='\.('"$ext_pattern"')$'
164
544
  for item in "${__candidates[@]}"; do
165
545
  if [[ -d "$item" ]]; then
166
546
  COMPREPLY+=("$item/")
167
- elif [[ ( -e "$item" || -L "$item" ) && "$item" =~ \.($ext_pattern)$ ]]; then
547
+ elif [[ ( -e "$item" || -L "$item" ) && "$item" =~ $ext_pattern ]]; then
168
548
  COMPREPLY+=("$item")
169
549
  fi
170
550
  done
@@ -183,7 +563,12 @@ function _drfed-server () {
183
563
  esac
184
564
 
185
565
  # Restore tilde prefix in completion results
186
- if [[ -n "$__tilde_prefix" ]]; then
566
+ if (( __filter_pattern )); then
567
+ __tilde_prefix="$__pattern_tilde_prefix"
568
+ __tilde_expanded="$__pattern_tilde_expanded"
569
+ fi
570
+ if [[ -n "$__tilde_prefix" &&
571
+ ( -z "$__quote" || $__file_quote_offset -gt 0 ) ]]; then
187
572
  local __i
188
573
  for __i in "${!COMPREPLY[@]}"; do
189
574
  COMPREPLY[$__i]="${COMPREPLY[$__i]/#$__tilde_expanded/$__tilde_prefix}"
@@ -198,22 +583,136 @@ function _drfed-server () {
198
583
  if [[ "$__failglob_was_set" == "1" ]]; then shopt -s failglob; fi
199
584
  if [[ "$__noglob_was_set" == "1" ]]; then set -f; fi
200
585
 
586
+ # Readline appends directory separators when it receives the full path.
587
+ # Midword quotes still need ours because replies omit the typed prefix.
588
+ if [[ -n "$__quote" && $__file_quote_offset -eq 0 ]]; then
589
+ local __reply_index
590
+ for ((__reply_index=__reply_start; __reply_index<${#COMPREPLY[@]}; __reply_index++)); do
591
+ COMPREPLY[__reply_index]="${COMPREPLY[__reply_index]%/}"
592
+ done
593
+ fi
594
+
595
+ # Readline replaces only the text after an open quote. Remove the
596
+ # already typed prefix so it is not inserted a second time.
597
+ # Joined replies are trimmed once against __remove after restoring option=,
598
+ # and keyed replies once their key has been restored.
599
+ if [[ -n "$__quote" && $__file_quote_offset -gt 0 && -z "$__reply_prefix" && -z "$insertion_prefix" ]]; then
600
+ local __quote_prefix="${__file_current:0:__file_quote_offset}"
601
+ local __reply_index
602
+ for ((__reply_index=__reply_start; __reply_index<${#COMPREPLY[@]}; __reply_index++)); do
603
+ COMPREPLY[__reply_index]="${COMPREPLY[__reply_index]#"$__quote_prefix"}"
604
+ done
605
+ fi
606
+
607
+ # Readline expands a leading tilde in a returned filename even when the
608
+ # user did not type one. Keep such local paths explicitly relative.
609
+ if [[ ( "$__raw_file_current" != "~"* || $__file_tilde_quoted == 1 ) && -z "$__tilde_prefix" ]]; then
610
+ local __reply_index
611
+ for ((__reply_index=__reply_start; __reply_index<${#COMPREPLY[@]}; __reply_index++)); do
612
+ if [[ "${COMPREPLY[__reply_index]}" =~ $__tilde_glob_pattern ]]; then
613
+ COMPREPLY[__reply_index]="./${COMPREPLY[__reply_index]}"
614
+ fi
615
+ done
616
+ fi
617
+
618
+ # Bash 5.3 leaves substitutions unescaped inside an open double quote.
619
+ # Earlier versions already escape them during filename processing.
620
+ if [[ "$__quote" == '"' &&
621
+ ( ${BASH_VERSINFO[0]} -gt 5 ||
622
+ ( ${BASH_VERSINFO[0]} -eq 5 && ${BASH_VERSINFO[1]} -ge 3 ) ) &&
623
+ $(type -t compopt) == builtin ]]; then
624
+ local __escaped_reply __escape_index __reply_index
625
+ for ((__reply_index=__reply_start; __reply_index<${#COMPREPLY[@]}; __reply_index++)); do
626
+ __escaped_reply=""
627
+ for ((__escape_index=0; __escape_index<${#COMPREPLY[__reply_index]}; __escape_index++)); do
628
+ __char="${COMPREPLY[__reply_index]:__escape_index:1}"
629
+ __next="${COMPREPLY[__reply_index]:__escape_index+1:1}"
630
+ if [[ "$__char" == '\' &&
631
+ ( "$__next" == '$' || "$__next" == '`' ) ]]; then
632
+ __escaped_reply+="\\$__char"
633
+ elif [[ "$__char" == '$' || "$__char" == '`' ]]; then
634
+ __escaped_reply+="\\$__char"
635
+ else
636
+ __escaped_reply+="$__char"
637
+ fi
638
+ done
639
+ COMPREPLY[__reply_index]="$__escaped_reply"
640
+ done
641
+ fi
642
+
201
643
  # Filter out hidden files unless requested
202
644
  if [[ "$hidden" != "1" && "$__inside_hidden_path" == "0" && "$__prefix_targets_hidden" == "0" ]]; then
203
645
  local filtered=()
204
646
  local __name
205
647
  for item in "${COMPREPLY[@]}"; do
206
648
  __name="${item%/}"; __name="${__name##*/}"
207
- [[ "$__name" != .* ]] && filtered+=("$item")
649
+ if [[ "$__name" != .* ]]; then
650
+ filtered+=("$item")
651
+ fi
208
652
  done
209
653
  COMPREPLY=("${filtered[@]}")
210
654
  fi
655
+ if [[ -n "$insertion_prefix" ]]; then
656
+ local __reply_index
657
+ for ((__reply_index=__reply_start; __reply_index<${#COMPREPLY[@]}; __reply_index++)); do
658
+ COMPREPLY[__reply_index]="$insertion_prefix${COMPREPLY[__reply_index]}"
659
+ done
660
+ if [[ -n "$__quote" && $__file_quote_offset -gt 0 && -z "$__reply_prefix" ]]; then
661
+ local __quote_prefix="${__key_current:0:__file_quote_offset}"
662
+ for ((__reply_index=__reply_start; __reply_index<${#COMPREPLY[@]}; __reply_index++)); do
663
+ COMPREPLY[__reply_index]="${COMPREPLY[__reply_index]#"$__quote_prefix"}"
664
+ done
665
+ fi
666
+ fi
667
+ if [[ ${#COMPREPLY[@]} -gt $__reply_start ]]; then __file_mode=1; fi
211
668
  else
212
669
  # Regular literal completion
213
670
  COMPREPLY+=("$line")
214
671
  fi
215
- done < <(drfed-server 'completion' 'bash' "${prev[@]}" "$current" 2>/dev/null)
672
+ for __word in "${COMPREPLY[@]}"; do
673
+ __replies+=("$__reply_prefix$__word")
674
+ done
675
+ done
676
+ COMPREPLY=()
677
+ for __word in "${__replies[@]}"; do
678
+ if [[ "${__word:0:${#__remove}}" == "$__remove" ]]; then
679
+ COMPREPLY+=("${__word:${#__remove}}")
680
+ fi
681
+ done
682
+ if (( ${#COMPREPLY[@]} > 1 )) && command -v sort >/dev/null 2>&1; then
683
+ # Sort shell-escaped keys, not filenames: each key occupies one line even
684
+ # when a candidate contains tabs or newlines. Keep the first occurrence's
685
+ # index, then restore the original order without evaluating escaped data.
686
+ # This works without associative arrays or NUL-aware sort on Bash 3.2.
687
+ local -a __unique_replies=()
688
+ local __index __key __last_key=""
689
+ while IFS= read -r __index; do
690
+ __unique_replies+=("${COMPREPLY[__index]}")
691
+ done < <(
692
+ for ((__index=0; __index<${#COMPREPLY[@]}; __index++)); do
693
+ printf '%q\t%d\n' "${COMPREPLY[__index]}" "$__index"
694
+ done |
695
+ LC_ALL=C sort -t $'\t' -k1,1 -k2,2n |
696
+ {
697
+ while IFS=$'\t' read -r __key __index; do
698
+ if [ "$__key" != "$__last_key" ]; then
699
+ printf '%s\n' "$__index"
700
+ __last_key="$__key"
701
+ fi
702
+ done
703
+ } | LC_ALL=C sort -n
704
+ )
705
+ COMPREPLY=("${__unique_replies[@]}")
706
+ fi
707
+ if [[ $__file_mode == 1 && $(type -t compopt) == builtin ]]; then
708
+ compopt -o filenames 2>/dev/null || true
709
+ fi
216
710
  }
217
711
 
218
- complete -F _drfed-server -- drfed-server
712
+ # Bash 3.2 has no compopt: use filename quoting for all candidates there.
713
+ if [[ $(type -t compopt) == builtin ]]; then
714
+ complete -F _drfed-server -- drfed-server
715
+ else
716
+ complete -o filenames -F _drfed-server -- drfed-server
717
+ fi
219
718