mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
Rename flag that fails expansions with command substitutions
SKIP_CMDSUBST does not pass through command substitutions, unlike SKIP_VARIABLES and SKIP_WILDCARDS.
This commit is contained in:
parent
126036c980
commit
68d1207d53
7 changed files with 20 additions and 24 deletions
|
@ -903,7 +903,7 @@ impl<'ctx> Completer<'ctx> {
|
||||||
&mut tmp,
|
&mut tmp,
|
||||||
self.expand_flags()
|
self.expand_flags()
|
||||||
| extra_expand_flags
|
| extra_expand_flags
|
||||||
| ExpandFlags::SKIP_CMDSUBST
|
| ExpandFlags::FAIL_ON_CMDSUBST
|
||||||
| ExpandFlags::SKIP_WILDCARDS,
|
| ExpandFlags::SKIP_WILDCARDS,
|
||||||
self.ctx,
|
self.ctx,
|
||||||
None,
|
None,
|
||||||
|
@ -930,7 +930,7 @@ impl<'ctx> Completer<'ctx> {
|
||||||
|
|
||||||
fn expand_flags(&self) -> ExpandFlags {
|
fn expand_flags(&self) -> ExpandFlags {
|
||||||
let mut result = ExpandFlags::empty();
|
let mut result = ExpandFlags::empty();
|
||||||
result.set(ExpandFlags::SKIP_CMDSUBST, self.flags.autosuggestion);
|
result.set(ExpandFlags::FAIL_ON_CMDSUBST, self.flags.autosuggestion);
|
||||||
result.set(ExpandFlags::FUZZY_MATCH, self.flags.fuzzy_match);
|
result.set(ExpandFlags::FUZZY_MATCH, self.flags.fuzzy_match);
|
||||||
result.set(ExpandFlags::GEN_DESCRIPTIONS, self.flags.descriptions);
|
result.set(ExpandFlags::GEN_DESCRIPTIONS, self.flags.descriptions);
|
||||||
result
|
result
|
||||||
|
@ -1164,7 +1164,7 @@ impl<'ctx> Completer<'ctx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let eflags = if is_autosuggest {
|
let eflags = if is_autosuggest {
|
||||||
ExpandFlags::SKIP_CMDSUBST
|
ExpandFlags::FAIL_ON_CMDSUBST
|
||||||
} else {
|
} else {
|
||||||
ExpandFlags::empty()
|
ExpandFlags::empty()
|
||||||
};
|
};
|
||||||
|
@ -1502,7 +1502,7 @@ impl<'ctx> Completer<'ctx> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut flags = self.expand_flags()
|
let mut flags = self.expand_flags()
|
||||||
| ExpandFlags::SKIP_CMDSUBST
|
| ExpandFlags::FAIL_ON_CMDSUBST
|
||||||
| ExpandFlags::FOR_COMPLETIONS
|
| ExpandFlags::FOR_COMPLETIONS
|
||||||
| ExpandFlags::PRESERVE_HOME_TILDES;
|
| ExpandFlags::PRESERVE_HOME_TILDES;
|
||||||
if !do_file {
|
if !do_file {
|
||||||
|
@ -1817,7 +1817,7 @@ impl<'ctx> Completer<'ctx> {
|
||||||
// VAR=(launch_missiles) cmd<tab>
|
// VAR=(launch_missiles) cmd<tab>
|
||||||
// should not launch missiles.
|
// should not launch missiles.
|
||||||
// Note we also do NOT send --on-variable events.
|
// Note we also do NOT send --on-variable events.
|
||||||
let expand_flags = ExpandFlags::SKIP_CMDSUBST;
|
let expand_flags = ExpandFlags::FAIL_ON_CMDSUBST;
|
||||||
let block = parser.push_block(Block::variable_assignment_block());
|
let block = parser.push_block(Block::variable_assignment_block());
|
||||||
for var_assign in var_assignments {
|
for var_assign in var_assignments {
|
||||||
let equals_pos = variable_assignment_equals_pos(var_assign)
|
let equals_pos = variable_assignment_equals_pos(var_assign)
|
||||||
|
@ -2185,7 +2185,7 @@ fn expand_command_token(ctx: &OperationContext<'_>, cmd_tok: &mut WString) -> bo
|
||||||
// Also we could expand wildcards.
|
// Also we could expand wildcards.
|
||||||
expand_one(
|
expand_one(
|
||||||
cmd_tok,
|
cmd_tok,
|
||||||
ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
||||||
ctx,
|
ctx,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
|
@ -32,8 +32,8 @@ bitflags! {
|
||||||
/// Set of flags controlling expansions.
|
/// Set of flags controlling expansions.
|
||||||
#[derive(Copy, Clone, Default)]
|
#[derive(Copy, Clone, Default)]
|
||||||
pub struct ExpandFlags : u16 {
|
pub struct ExpandFlags : u16 {
|
||||||
/// Skip command substitutions.
|
/// Fail expansion if there is a command substitution.
|
||||||
const SKIP_CMDSUBST = 1 << 0;
|
const FAIL_ON_CMDSUBST = 1 << 0;
|
||||||
/// Skip variable expansion.
|
/// Skip variable expansion.
|
||||||
const SKIP_VARIABLES = 1 << 1;
|
const SKIP_VARIABLES = 1 << 1;
|
||||||
/// Skip wildcard expansion.
|
/// Skip wildcard expansion.
|
||||||
|
@ -132,8 +132,6 @@ pub const PROCESS_EXPAND_SELF_STR: &wstr = L!("%self");
|
||||||
///
|
///
|
||||||
/// \param input The parameter to expand
|
/// \param input The parameter to expand
|
||||||
/// \param output The list to which the result will be appended.
|
/// \param output The list to which the result will be appended.
|
||||||
/// \param flags Specifies if any expansion pass should be skipped. Legal values are any combination
|
|
||||||
/// of skip_cmdsubst skip_variables and skip_wildcards
|
|
||||||
/// \param ctx The parser, variables, and cancellation checker for this operation. The parser may
|
/// \param ctx The parser, variables, and cancellation checker for this operation. The parser may
|
||||||
/// be null. \param errors Resulting errors, or nullptr to ignore
|
/// be null. \param errors Resulting errors, or nullptr to ignore
|
||||||
///
|
///
|
||||||
|
@ -170,8 +168,6 @@ pub fn expand_to_receiver(
|
||||||
/// string. This is used for expanding command names.
|
/// string. This is used for expanding command names.
|
||||||
///
|
///
|
||||||
/// \param inout_str The parameter to expand in-place
|
/// \param inout_str The parameter to expand in-place
|
||||||
/// \param flags Specifies if any expansion pass should be skipped. Legal values are any combination
|
|
||||||
/// of skip_cmdsubst skip_variables and skip_wildcards
|
|
||||||
/// \param ctx The parser, variables, and cancellation checker for this operation. The parser may be
|
/// \param ctx The parser, variables, and cancellation checker for this operation. The parser may be
|
||||||
/// null.
|
/// null.
|
||||||
/// \param errors Resulting errors, or nullptr to ignore
|
/// \param errors Resulting errors, or nullptr to ignore
|
||||||
|
@ -222,7 +218,7 @@ pub fn expand_to_command_and_args(
|
||||||
return ExpandResult::ok();
|
return ExpandResult::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut eflags = ExpandFlags::SKIP_CMDSUBST;
|
let mut eflags = ExpandFlags::FAIL_ON_CMDSUBST;
|
||||||
if skip_wildcards {
|
if skip_wildcards {
|
||||||
eflags |= ExpandFlags::SKIP_WILDCARDS;
|
eflags |= ExpandFlags::SKIP_WILDCARDS;
|
||||||
}
|
}
|
||||||
|
@ -851,7 +847,7 @@ fn expand_braces(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: this code looks very fishy, apparently it has never worked.
|
// Note: this code looks very fishy, apparently it has never worked.
|
||||||
return expand_braces(synth, ExpandFlags::SKIP_CMDSUBST, out, errors);
|
return expand_braces(synth, ExpandFlags::FAIL_ON_CMDSUBST, out, errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1239,7 +1235,7 @@ impl<'a, 'b, 'c> Expander<'a, 'b, 'c> {
|
||||||
mut errors: Option<&'a mut ParseErrorList>,
|
mut errors: Option<&'a mut ParseErrorList>,
|
||||||
) -> ExpandResult {
|
) -> ExpandResult {
|
||||||
assert!(
|
assert!(
|
||||||
flags.contains(ExpandFlags::SKIP_CMDSUBST) || ctx.has_parser(),
|
flags.contains(ExpandFlags::FAIL_ON_CMDSUBST) || ctx.has_parser(),
|
||||||
"Must have a parser if not skipping command substitutions"
|
"Must have a parser if not skipping command substitutions"
|
||||||
);
|
);
|
||||||
// Early out. If we're not completing, and there's no magic in the input, we're done.
|
// Early out. If we're not completing, and there's no magic in the input, we're done.
|
||||||
|
@ -1313,7 +1309,7 @@ impl<'a, 'b, 'c> Expander<'a, 'b, 'c> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stage_cmdsubst(&mut self, input: WString, out: &mut CompletionReceiver) -> ExpandResult {
|
fn stage_cmdsubst(&mut self, input: WString, out: &mut CompletionReceiver) -> ExpandResult {
|
||||||
if self.flags.contains(ExpandFlags::SKIP_CMDSUBST) {
|
if self.flags.contains(ExpandFlags::FAIL_ON_CMDSUBST) {
|
||||||
let mut cursor = 0;
|
let mut cursor = 0;
|
||||||
let mut start = 0;
|
let mut start = 0;
|
||||||
let mut end = 0;
|
let mut end = 0;
|
||||||
|
|
|
@ -336,7 +336,7 @@ pub fn autosuggest_validate_from_history(
|
||||||
|
|
||||||
// We handle cd specially.
|
// We handle cd specially.
|
||||||
if parsed_command == "cd" && !cd_dir.is_empty() {
|
if parsed_command == "cd" && !cd_dir.is_empty() {
|
||||||
if expand_one(&mut cd_dir, ExpandFlags::SKIP_CMDSUBST, ctx, None) {
|
if expand_one(&mut cd_dir, ExpandFlags::FAIL_ON_CMDSUBST, ctx, None) {
|
||||||
if string_prefixes_string(&cd_dir, L!("--help"))
|
if string_prefixes_string(&cd_dir, L!("--help"))
|
||||||
|| string_prefixes_string(&cd_dir, L!("-h"))
|
|| string_prefixes_string(&cd_dir, L!("-h"))
|
||||||
{
|
{
|
||||||
|
@ -1149,7 +1149,7 @@ impl<'s> Highlighter<'s> {
|
||||||
if cmd_is_cd {
|
if cmd_is_cd {
|
||||||
// Mark this as an error if it's not 'help' and not a valid cd path.
|
// Mark this as an error if it's not 'help' and not a valid cd path.
|
||||||
let mut param = arg.source(self.buff).to_owned();
|
let mut param = arg.source(self.buff).to_owned();
|
||||||
if expand_one(&mut param, ExpandFlags::SKIP_CMDSUBST, self.ctx, None) {
|
if expand_one(&mut param, ExpandFlags::FAIL_ON_CMDSUBST, self.ctx, None) {
|
||||||
let is_help = string_prefixes_string(¶m, L!("--help"))
|
let is_help = string_prefixes_string(¶m, L!("--help"))
|
||||||
|| string_prefixes_string(¶m, L!("-h"));
|
|| string_prefixes_string(¶m, L!("-h"));
|
||||||
if !is_help {
|
if !is_help {
|
||||||
|
@ -1221,7 +1221,7 @@ impl<'s> Highlighter<'s> {
|
||||||
target_is_valid = true;
|
target_is_valid = true;
|
||||||
} else if contains_pending_variable(&self.pending_variables, &target) {
|
} else if contains_pending_variable(&self.pending_variables, &target) {
|
||||||
target_is_valid = true;
|
target_is_valid = true;
|
||||||
} else if !expand_one(&mut target, ExpandFlags::SKIP_CMDSUBST, self.ctx, None) {
|
} else if !expand_one(&mut target, ExpandFlags::FAIL_ON_CMDSUBST, self.ctx, None) {
|
||||||
// Could not be expanded.
|
// Could not be expanded.
|
||||||
target_is_valid = false;
|
target_is_valid = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1976,7 +1976,7 @@ pub fn expand_and_detect_paths<P: IntoIterator<Item = WString>>(
|
||||||
let mut expanded_path = path.clone();
|
let mut expanded_path = path.clone();
|
||||||
if expand_one(
|
if expand_one(
|
||||||
&mut expanded_path,
|
&mut expanded_path,
|
||||||
ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
||||||
&ctx,
|
&ctx,
|
||||||
None,
|
None,
|
||||||
) && path_is_valid(&expanded_path, &working_directory)
|
) && path_is_valid(&expanded_path, &working_directory)
|
||||||
|
@ -2004,7 +2004,7 @@ pub fn all_paths_are_valid<P: IntoIterator<Item = WString>>(
|
||||||
}
|
}
|
||||||
if !expand_one(
|
if !expand_one(
|
||||||
&mut path,
|
&mut path,
|
||||||
ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
||||||
ctx,
|
ctx,
|
||||||
None,
|
None,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -475,7 +475,7 @@ impl<'a> ParseExecutionContext {
|
||||||
let forbidden = !cmd.is_empty()
|
let forbidden = !cmd.is_empty()
|
||||||
&& expand_one(
|
&& expand_one(
|
||||||
&mut cmd,
|
&mut cmd,
|
||||||
ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_VARIABLES,
|
ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_VARIABLES,
|
||||||
ctx,
|
ctx,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1638,7 +1638,7 @@ fn detect_errors_in_decorated_statement(
|
||||||
let mut command = unexp_command.to_owned();
|
let mut command = unexp_command.to_owned();
|
||||||
if expand_one(
|
if expand_one(
|
||||||
&mut command,
|
&mut command,
|
||||||
ExpandFlags::SKIP_CMDSUBST,
|
ExpandFlags::FAIL_ON_CMDSUBST,
|
||||||
&OperationContext::empty(),
|
&OperationContext::empty(),
|
||||||
match parse_errors {
|
match parse_errors {
|
||||||
Some(pe) => Some(pe),
|
Some(pe) => Some(pe),
|
||||||
|
|
|
@ -4811,7 +4811,7 @@ fn try_expand_wildcard(
|
||||||
|
|
||||||
// We do wildcards only.
|
// We do wildcards only.
|
||||||
|
|
||||||
let flags = ExpandFlags::SKIP_CMDSUBST
|
let flags = ExpandFlags::FAIL_ON_CMDSUBST
|
||||||
| ExpandFlags::SKIP_VARIABLES
|
| ExpandFlags::SKIP_VARIABLES
|
||||||
| ExpandFlags::PRESERVE_HOME_TILDES;
|
| ExpandFlags::PRESERVE_HOME_TILDES;
|
||||||
let mut expanded = CompletionList::new();
|
let mut expanded = CompletionList::new();
|
||||||
|
|
Loading…
Reference in a new issue