mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +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,
|
||||
self.expand_flags()
|
||||
| extra_expand_flags
|
||||
| ExpandFlags::SKIP_CMDSUBST
|
||||
| ExpandFlags::FAIL_ON_CMDSUBST
|
||||
| ExpandFlags::SKIP_WILDCARDS,
|
||||
self.ctx,
|
||||
None,
|
||||
|
@ -930,7 +930,7 @@ impl<'ctx> Completer<'ctx> {
|
|||
|
||||
fn expand_flags(&self) -> ExpandFlags {
|
||||
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::GEN_DESCRIPTIONS, self.flags.descriptions);
|
||||
result
|
||||
|
@ -1164,7 +1164,7 @@ impl<'ctx> Completer<'ctx> {
|
|||
};
|
||||
|
||||
let eflags = if is_autosuggest {
|
||||
ExpandFlags::SKIP_CMDSUBST
|
||||
ExpandFlags::FAIL_ON_CMDSUBST
|
||||
} else {
|
||||
ExpandFlags::empty()
|
||||
};
|
||||
|
@ -1502,7 +1502,7 @@ impl<'ctx> Completer<'ctx> {
|
|||
return;
|
||||
}
|
||||
let mut flags = self.expand_flags()
|
||||
| ExpandFlags::SKIP_CMDSUBST
|
||||
| ExpandFlags::FAIL_ON_CMDSUBST
|
||||
| ExpandFlags::FOR_COMPLETIONS
|
||||
| ExpandFlags::PRESERVE_HOME_TILDES;
|
||||
if !do_file {
|
||||
|
@ -1817,7 +1817,7 @@ impl<'ctx> Completer<'ctx> {
|
|||
// VAR=(launch_missiles) cmd<tab>
|
||||
// should not launch missiles.
|
||||
// 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());
|
||||
for var_assign in var_assignments {
|
||||
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.
|
||||
expand_one(
|
||||
cmd_tok,
|
||||
ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
||||
ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
||||
ctx,
|
||||
None,
|
||||
)
|
||||
|
|
|
@ -32,8 +32,8 @@ bitflags! {
|
|||
/// Set of flags controlling expansions.
|
||||
#[derive(Copy, Clone, Default)]
|
||||
pub struct ExpandFlags : u16 {
|
||||
/// Skip command substitutions.
|
||||
const SKIP_CMDSUBST = 1 << 0;
|
||||
/// Fail expansion if there is a command substitution.
|
||||
const FAIL_ON_CMDSUBST = 1 << 0;
|
||||
/// Skip variable expansion.
|
||||
const SKIP_VARIABLES = 1 << 1;
|
||||
/// Skip wildcard expansion.
|
||||
|
@ -132,8 +132,6 @@ pub const PROCESS_EXPAND_SELF_STR: &wstr = L!("%self");
|
|||
///
|
||||
/// \param input The parameter to expand
|
||||
/// \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
|
||||
/// 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.
|
||||
///
|
||||
/// \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
|
||||
/// null.
|
||||
/// \param errors Resulting errors, or nullptr to ignore
|
||||
|
@ -222,7 +218,7 @@ pub fn expand_to_command_and_args(
|
|||
return ExpandResult::ok();
|
||||
}
|
||||
|
||||
let mut eflags = ExpandFlags::SKIP_CMDSUBST;
|
||||
let mut eflags = ExpandFlags::FAIL_ON_CMDSUBST;
|
||||
if skip_wildcards {
|
||||
eflags |= ExpandFlags::SKIP_WILDCARDS;
|
||||
}
|
||||
|
@ -851,7 +847,7 @@ fn expand_braces(
|
|||
}
|
||||
|
||||
// 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>,
|
||||
) -> ExpandResult {
|
||||
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"
|
||||
);
|
||||
// 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 {
|
||||
if self.flags.contains(ExpandFlags::SKIP_CMDSUBST) {
|
||||
if self.flags.contains(ExpandFlags::FAIL_ON_CMDSUBST) {
|
||||
let mut cursor = 0;
|
||||
let mut start = 0;
|
||||
let mut end = 0;
|
||||
|
|
|
@ -336,7 +336,7 @@ pub fn autosuggest_validate_from_history(
|
|||
|
||||
// We handle cd specially.
|
||||
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"))
|
||||
|| string_prefixes_string(&cd_dir, L!("-h"))
|
||||
{
|
||||
|
@ -1149,7 +1149,7 @@ impl<'s> Highlighter<'s> {
|
|||
if cmd_is_cd {
|
||||
// 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();
|
||||
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"))
|
||||
|| string_prefixes_string(¶m, L!("-h"));
|
||||
if !is_help {
|
||||
|
@ -1221,7 +1221,7 @@ impl<'s> Highlighter<'s> {
|
|||
target_is_valid = true;
|
||||
} else if contains_pending_variable(&self.pending_variables, &target) {
|
||||
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.
|
||||
target_is_valid = false;
|
||||
} else {
|
||||
|
|
|
@ -1976,7 +1976,7 @@ pub fn expand_and_detect_paths<P: IntoIterator<Item = WString>>(
|
|||
let mut expanded_path = path.clone();
|
||||
if expand_one(
|
||||
&mut expanded_path,
|
||||
ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
||||
ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
||||
&ctx,
|
||||
None,
|
||||
) && path_is_valid(&expanded_path, &working_directory)
|
||||
|
@ -2004,7 +2004,7 @@ pub fn all_paths_are_valid<P: IntoIterator<Item = WString>>(
|
|||
}
|
||||
if !expand_one(
|
||||
&mut path,
|
||||
ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
||||
ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_WILDCARDS,
|
||||
ctx,
|
||||
None,
|
||||
) {
|
||||
|
|
|
@ -475,7 +475,7 @@ impl<'a> ParseExecutionContext {
|
|||
let forbidden = !cmd.is_empty()
|
||||
&& expand_one(
|
||||
&mut cmd,
|
||||
ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_VARIABLES,
|
||||
ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_VARIABLES,
|
||||
ctx,
|
||||
None,
|
||||
)
|
||||
|
|
|
@ -1638,7 +1638,7 @@ fn detect_errors_in_decorated_statement(
|
|||
let mut command = unexp_command.to_owned();
|
||||
if expand_one(
|
||||
&mut command,
|
||||
ExpandFlags::SKIP_CMDSUBST,
|
||||
ExpandFlags::FAIL_ON_CMDSUBST,
|
||||
&OperationContext::empty(),
|
||||
match parse_errors {
|
||||
Some(pe) => Some(pe),
|
||||
|
|
|
@ -4811,7 +4811,7 @@ fn try_expand_wildcard(
|
|||
|
||||
// We do wildcards only.
|
||||
|
||||
let flags = ExpandFlags::SKIP_CMDSUBST
|
||||
let flags = ExpandFlags::FAIL_ON_CMDSUBST
|
||||
| ExpandFlags::SKIP_VARIABLES
|
||||
| ExpandFlags::PRESERVE_HOME_TILDES;
|
||||
let mut expanded = CompletionList::new();
|
||||
|
|
Loading…
Reference in a new issue