diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-03 01:41:04 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-03 01:41:04 +0800 |
| commit | c01c3a53a5e117c60df846de7d2c1bdc43627a0b (patch) | |
| tree | dab26ea4a56c66f01fcc49f16a1949a5237b57a4 | |
| parent | 88c3cbb27cc840d38e16ae8ab39c9a168a653a88 (diff) | |
fix(shell-ctx): distinguish missing -F from empty flag
Previously, an absent -F and a present -F without a value both
mapped to "unknown". Now, a -F with no value maps to an empty
shell flag, while a missing -F remains "unknown".
| -rw-r--r-- | mingling_core/src/comp/shell_ctx.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/mingling_core/src/comp/shell_ctx.rs b/mingling_core/src/comp/shell_ctx.rs index 8efbc9d..734b5d2 100644 --- a/mingling_core/src/comp/shell_ctx.rs +++ b/mingling_core/src/comp/shell_ctx.rs @@ -50,8 +50,14 @@ impl TryFrom<Vec<String>> for ShellContext { let word_index = special_argument!(args, "-i") .and_then(|s| s.parse().ok()) .unwrap_or_default(); - let shell_flag = special_argument!(args, "-F") - .map_or(ShellFlag::Other("unknown".to_string()), ShellFlag::from); + // Distinguish "-F absent" (unknown shell) from "-F present without a value" (empty shell) + let has_shell_flag = args.iter().any(|arg| arg == "-F"); + let shell_flag = if has_shell_flag { + special_argument!(args, "-F") + .map_or_else(|| ShellFlag::Other(String::new()), ShellFlag::from) + } else { + ShellFlag::Other("unknown".to_string()) + }; let all_words = command_line .split_whitespace() |
