Repository navigation
Description
fish version: 4.9.3
OS: macOS & Arch Linux
Terminal: WezTerm
Confirmed that the problem occurs without third-party customizations
I'm seeing a truncated completion suggestion with a directory like this:
my-project/
├── Dockerfile
└── docs/
If I try to complete docs from outside the directory, I see this:
$ ls my-project/d<TAB>
my-project/Dockerfile …/
I expected to see this instead:
$ ls my-project/d<TAB>
my-project/Dockerfile …/docs/
I believe the issue arises from this code:
fish-shell/src/reader/reader.rs
Lines 7182 to 7192 in f0d874a
| let truncated = &full[full.len() - PREFIX_MAX_LEN..]; | |
| let (i, last_component) = truncated.split('/').enumerate().last().unwrap(); | |
| if i == 0 { | |
| // No path separators were found in the common prefix, so we can't collapse | |
| // any further | |
| prefix.push_utfstr(&truncated); | |
| } else { | |
| // Discard any parent directories and include whats left | |
| prefix.push('/'); | |
| prefix.push_utfstr(last_component); | |
| } |
(The directory name has to be longer than PREFIX_MAX_LEN (9) to hit the bug)
It appears that fish sees the / at the end of docs/ since it's a directory and truncates the whole thing to an ellipsis, instead of just the prefix.
I started working on a fix for this but when I ran the test suite, I discovered that this might actually be intended behavior? There's a test (added in 2f6b1ea to fix #12249) asserting that the subdirectory is fully replaced by an ellipsis:
fish-shell/tests/checks/tmux-complete2.fish
Lines 40 to 46 in f0d874a
| mkdir -p clang/include | |
| touch clang/INSTALL.txt | |
| isolated-tmux send-keys C-u ': clang/in' Tab | |
| tmux-sleep | |
| isolated-tmux capture-pane -p | |
| # CHECK: prompt 1> : clang/include/ | |
| # CHECK: clang/INSTALL.txt …/ |
That felt a little strange to me so I wanted to raise the question here before opening a PR for it. Is that intended or should we change the behavior so it doesn't truncate the entire subdirectory name?
Activity
faho commentedon Nov 22, 2026
Nah this is clearly bogus - the last component should always be shown. Just a common issue of not correctly ignoring a trailing "/".