mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-29 10:31:14 -03:00
Compare commits
5 Commits
3cb939c9a8
...
5eb7687a64
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5eb7687a64 | ||
|
|
8d6426295e | ||
|
|
85e76ba356 | ||
|
|
fee4288122 | ||
|
|
413246a93d |
@@ -32,8 +32,7 @@
|
||||
use fish_util::wcsfilecmp;
|
||||
use fish_wcstringutil::{
|
||||
StringFuzzyMatch, string_fuzzy_match_string, string_prefixes_string,
|
||||
string_prefixes_string_case_insensitive, string_suffixes_string_case_insensitive,
|
||||
strip_executable_suffix,
|
||||
string_suffixes_string_case_insensitive, strip_executable_suffix,
|
||||
};
|
||||
use fish_widestring::{WExt as _, charptr2wcstring};
|
||||
use std::{
|
||||
@@ -159,7 +158,10 @@ pub fn new(
|
||||
r#match: StringFuzzyMatch, /* = exact_match */
|
||||
flags: CompleteFlags,
|
||||
) -> Self {
|
||||
let flags = resolve_auto_space(&completion, flags);
|
||||
let mut flags = resolve_auto_space(&completion, flags);
|
||||
if r#match.requires_full_replacement() {
|
||||
flags |= CompleteFlags::REPLACES_TOKEN;
|
||||
}
|
||||
Self {
|
||||
completion,
|
||||
description,
|
||||
@@ -1483,14 +1485,12 @@ fn complete_param_for_command(
|
||||
continue;
|
||||
};
|
||||
|
||||
let mut offset = 0;
|
||||
let mut flags = CompleteFlags::empty();
|
||||
|
||||
if r#match.requires_full_replacement() {
|
||||
flags = CompleteFlags::REPLACES_TOKEN;
|
||||
let offset = if r#match.requires_full_replacement() {
|
||||
0
|
||||
} else {
|
||||
offset = s.len();
|
||||
}
|
||||
s.len()
|
||||
};
|
||||
let completion = whole_opt.slice_from(offset);
|
||||
|
||||
// does this switch have any known arguments
|
||||
let has_arg = !o.comp.is_empty();
|
||||
@@ -1502,14 +1502,14 @@ fn complete_param_for_command(
|
||||
// a completion. By default we avoid using '=' and instead rely on '--switch
|
||||
// switch-arg', since it is more commonly supported by homebrew getopt-like
|
||||
// functions.
|
||||
let completion = sprintf!("%s=", whole_opt.slice_from(offset));
|
||||
let completion = sprintf!("%s=", completion);
|
||||
|
||||
// Append a long-style option with a mandatory trailing equal sign
|
||||
if !self.completions.add(Completion::new(
|
||||
completion,
|
||||
o.desc.localize().to_owned(),
|
||||
StringFuzzyMatch::exact_match(),
|
||||
flags | CompleteFlags::NO_SPACE,
|
||||
r#match,
|
||||
CompleteFlags::NO_SPACE,
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1517,10 +1517,10 @@ fn complete_param_for_command(
|
||||
|
||||
// Append a long-style option
|
||||
if !self.completions.add(Completion::new(
|
||||
whole_opt.slice_from(offset).to_owned(),
|
||||
completion.to_owned(),
|
||||
o.desc.localize().to_owned(),
|
||||
StringFuzzyMatch::exact_match(),
|
||||
flags,
|
||||
r#match,
|
||||
CompleteFlags::empty(),
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1666,7 +1666,7 @@ fn complete_variable(&mut self, s: &wstr, start_offset: usize) -> bool {
|
||||
// Take only the suffix.
|
||||
env_name.slice_from(varlen).to_owned()
|
||||
} else {
|
||||
flags |= CompleteFlags::REPLACES_TOKEN | CompleteFlags::DONT_ESCAPE;
|
||||
flags |= CompleteFlags::DONT_ESCAPE;
|
||||
whole_var.slice_to(start_offset).to_owned() + env_name.as_utfstr()
|
||||
};
|
||||
|
||||
@@ -1823,30 +1823,23 @@ fn getpwent_name() -> Option<WString> {
|
||||
break;
|
||||
}
|
||||
|
||||
if string_prefixes_string(user_name, &pw_name) {
|
||||
if let Some(r#match) = StringFuzzyMatch::try_create(user_name, &pw_name, true) {
|
||||
let desc = wgettext_fmt!(COMPLETE_USER_DESC, &pw_name);
|
||||
// Append a user name.
|
||||
// TODO: propagate overflow?
|
||||
let mut flags = CompleteFlags::NO_SPACE;
|
||||
if r#match.requires_full_replacement() {
|
||||
flags |= CompleteFlags::DONT_ESCAPE;
|
||||
}
|
||||
let _ = self.completions.add(Completion::new(
|
||||
pw_name.slice_from(name_len).to_owned(),
|
||||
if r#match.requires_full_replacement() {
|
||||
sprintf!("~%s", &pw_name)
|
||||
} else {
|
||||
pw_name.slice_from(name_len).to_owned()
|
||||
},
|
||||
desc,
|
||||
StringFuzzyMatch::exact_match(),
|
||||
CompleteFlags::NO_SPACE,
|
||||
));
|
||||
result = true;
|
||||
} else if string_prefixes_string_case_insensitive(user_name, &pw_name) {
|
||||
let name = sprintf!("~%s", &pw_name);
|
||||
let desc = wgettext_fmt!(COMPLETE_USER_DESC, &pw_name);
|
||||
|
||||
// Append a user name
|
||||
// TODO: propagate overflow?
|
||||
let _ = self.completions.add(Completion::new(
|
||||
name,
|
||||
desc,
|
||||
StringFuzzyMatch::exact_match(),
|
||||
CompleteFlags::REPLACES_TOKEN
|
||||
| CompleteFlags::DONT_ESCAPE
|
||||
| CompleteFlags::NO_SPACE,
|
||||
r#match,
|
||||
flags,
|
||||
));
|
||||
result = true;
|
||||
}
|
||||
|
||||
@@ -7026,9 +7026,11 @@ fn handle_completions(&mut self, token_range: Range<usize>, mut comp: Vec<Comple
|
||||
|
||||
comp.retain(|c| !c.replaces_token() || reader_can_replace(&tok, c.flags));
|
||||
|
||||
for c in &mut comp {
|
||||
if !will_replace_token && c.replaces_token() {
|
||||
c.flags |= CompleteFlags::SUPPRESS_PAGER_PREFIX;
|
||||
if !will_replace_token {
|
||||
for c in &mut comp {
|
||||
if c.replaces_token() {
|
||||
c.flags |= CompleteFlags::SUPPRESS_PAGER_PREFIX;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -149,16 +149,11 @@ fn wildcard_complete_internal(
|
||||
|
||||
// Note: out_completion may be empty if the completion really is empty, e.g. tab-completing
|
||||
// 'foo' when a file 'foo' exists.
|
||||
let local_flags = if full_replacement {
|
||||
flags | CompleteFlags::REPLACES_TOKEN
|
||||
} else {
|
||||
flags
|
||||
};
|
||||
if !out.add(Completion::new(
|
||||
out_completion.to_owned(),
|
||||
out_desc,
|
||||
m,
|
||||
local_flags,
|
||||
flags,
|
||||
)) {
|
||||
return WildcardResult::Overflow;
|
||||
}
|
||||
|
||||
@@ -727,3 +727,9 @@ complete -c foo -a "foo\\"
|
||||
|
||||
complete -C
|
||||
# CHECKERR: complete: Can not get commandline in non-interactive mode
|
||||
|
||||
if string match -rq -- '^[a-z]+$' $USER
|
||||
set -l first_letter_wrong_case (string sub -l 1 -- $USER | string upper)
|
||||
string match -rq -- "$USER\t.*" (complete -C "echo ~$first_letter_wrong_case")
|
||||
or echo "`complete -C'echo ~$first_letter_wrong_case'` did not yield $USER"
|
||||
end
|
||||
|
||||
30
tests/checks/tmux-complete4.fish
Normal file
30
tests/checks/tmux-complete4.fish
Normal file
@@ -0,0 +1,30 @@
|
||||
#RUN: %fish %s
|
||||
#REQUIRES: command -v tmux
|
||||
#REQUIRES: uname -r | grep -qv Microsoft
|
||||
|
||||
isolated-tmux-start -C '
|
||||
complete : -s c -l clip
|
||||
complete : -s q -l qrcode
|
||||
set -g fish_autosuggestion_enabled 0
|
||||
'
|
||||
touch somefile1
|
||||
touch somefile2
|
||||
|
||||
isolated-tmux send-keys C-l ': -c'
|
||||
|
||||
function tab
|
||||
isolated-tmux send-keys Tab
|
||||
tmux-sleep
|
||||
isolated-tmux capture-pane -p | awk '/./ { print "[" $0 "]" }'
|
||||
end
|
||||
|
||||
tab
|
||||
# CHECK: [prompt 0> : -cq]
|
||||
|
||||
tab
|
||||
# CHECK: [prompt 0> : -cq somefile]
|
||||
# CHECK: [somefile1 somefile2]
|
||||
|
||||
tab
|
||||
# CHECK: [prompt 0> : -cq somefile1]
|
||||
# CHECK: [somefile1 somefile2]
|
||||
Reference in New Issue
Block a user