Skip to content

Commit 9847e6e

Browse files
Beinseziiysthakur
andauthoredMar 25, 2025
COOKBOOK/EXTERNAL_COMPLETERS.MD Add filepath escape troubleshooting (#1844)
* Update external_completers.md Add troubleshooting category for filepath escapes * Update external_completers.md * Update cookbook/external_completers.md Co-authored-by: Yash Thakur <45539777+ysthakur@users.noreply.github.com> --------- Co-authored-by: Yash Thakur <45539777+ysthakur@users.noreply.github.com>
1 parent 1942623 commit 9847e6e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed
 

‎cookbook/external_completers.md

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ let fish_completer = {|spans|
2323
fish --command $'complete "--do-complete=($spans | str join " ")"'
2424
| from tsv --flexible --noheaders --no-infer
2525
| rename value description
26+
| update value {
27+
if ($in | path exists) {$'"($in | str replace "\"" "\\\"" )"'} else {$in}
28+
}
2629
}
2730
```
2831

@@ -31,6 +34,7 @@ A couple of things to note on this command:
3134
- The fish completer will return lines of text, each one holding the `value` and `description` separated by a tab. The `description` can be missing, and in that case there won't be a tab after the `value`. If that happens, `from tsv` will fail, so we add the `--flexible` flag.
3235
- The output of the fish completer does not contain a header (name of the columns), so we add `--noheaders` to prevent `from tsv` from treating the first row as headers and later give the columns their names using `rename`.
3336
- `--no-infer` is optional. `from tsv` will infer the data type of the result, so a numeric value like some git hashes will be inferred as a number. `--no-infer` will keep everything as a string. It doesn't make a difference in practice but it will print a more consistent output if the completer is ran on it's own.
37+
- Since fish only supports POSIX style escapes for file paths (`file\ name.txt`, etc.), file paths completed by fish will not be quoted or escaped properly on external commands. Nushell does not parse POSIX escapes, so we need to do this conversion manually such as by testing if the items are valid paths as shown in the example. This simple approach is imperfect, but it should cover 99.9% of use cases.
3438

3539
### Zoxide completer
3640

0 commit comments

Comments
 (0)
Failed to load comments.