mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-23 21:31:14 -03:00
Remove directory name prefix in truncated completions
Sometimes, the dirname of a completion is much longer than the basename. When the dirname is the same for many completions, a long common dirname prefix makes it hard to see the interesting differences in the basenames. Fix this by collapsing the dirname prefix to "…/". In future, we should find a generic way to collapse completions that don't contain slashes. Closes #8618 Closes #11250
This commit is contained in:
committed by
Johannes Altmanninger
parent
17c072b4bf
commit
0dbfb4ccb1
@@ -4,6 +4,7 @@ fish 4.1.0 (released ???)
|
||||
Notable improvements and fixes
|
||||
------------------------------
|
||||
- Compound commands (``begin; echo 1; echo 2; end``) can now be now be abbreviated using braces (``{ echo1; echo 2 }``), like in other shells.
|
||||
- When tab completion results are truncated, any common directory name is omitted.
|
||||
|
||||
Deprecations and removed features
|
||||
---------------------------------
|
||||
|
||||
@@ -6497,10 +6497,21 @@ fn handle_completions(&mut self, token_range: Range<usize>) -> bool {
|
||||
prefix.push_utfstr(&tok);
|
||||
prefix.push_utfstr(&common_prefix);
|
||||
} else {
|
||||
// Append just the end of the string.
|
||||
// Collapse parent directories and append end of string
|
||||
prefix.push(get_ellipsis_char());
|
||||
|
||||
let full = tok + &common_prefix[..];
|
||||
prefix.push_utfstr(&full[full.len() - PREFIX_MAX_LEN..]);
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
// Update the pager data.
|
||||
|
||||
26
tests/checks/tmux-prefix.fish
Normal file
26
tests/checks/tmux-prefix.fish
Normal file
@@ -0,0 +1,26 @@
|
||||
#RUN: %fish %s
|
||||
#REQUIRES: command -v tmux
|
||||
#REQUIRES: test -z "$CI"
|
||||
|
||||
isolated-tmux-start
|
||||
|
||||
# Check no collapse
|
||||
mkdir -p a/b
|
||||
echo > a/b/f1
|
||||
echo > a/b/f2
|
||||
isolated-tmux send-keys 'HOME=$PWD ls ~/a/b/' Tab
|
||||
tmux-sleep
|
||||
isolated-tmux capture-pane -p
|
||||
# CHECK: prompt 0> HOME=$PWD ls ~/a/b/f
|
||||
# CHECK: ~/a/b/f1 ~/a/b/f2
|
||||
|
||||
# Check collapse
|
||||
isolated-tmux send-keys C-c
|
||||
mkdir -p dddddd/eeeeee
|
||||
echo > dddddd/eeeeee/file1
|
||||
echo > dddddd/eeeeee/file2
|
||||
isolated-tmux send-keys 'HOME=$PWD ls ~/dddddd/eeeeee/' Tab
|
||||
tmux-sleep
|
||||
isolated-tmux capture-pane -p
|
||||
# CHECK: prompt 0> HOME=$PWD ls ~/dddddd/eeeeee/file
|
||||
# CHECK: …/file1 …/file2
|
||||
Reference in New Issue
Block a user