Highlight valid paths in redirection targets

Closes #12260
This commit is contained in:
Lennard Hofmann
2026-01-03 12:46:33 +01:00
committed by Johannes Altmanninger
parent 62cc117c12
commit 6e7353170a
2 changed files with 13 additions and 1 deletions

View File

@@ -10,6 +10,10 @@ This release fixes the following problems identified in fish 4.3.0:
- The sample prompts and themes are correctly installed (:issue:`12241`).
- Last line of command output could be hidden when missing newline (:issue:`12246`).
Interactive improvements
------------------------
- Existing file paths in redirection targets such as ``> file.txt`` are now highlighted using :envvar:`fish_color_valid_path`, indicating that ``file.txt`` will be clobbered (:issue:`12260`).
For distributors and developers
-------------------------------
- The CMake option ``WITH_GETTEXT`` has been renamed to ``WITH_MESSAGE_LOCALIZATION``, to reflect that it toggles localization independently of the backend used in the implementation.

View File

@@ -985,6 +985,11 @@ fn visit_redirection(&mut self, redir: &Redirection) {
HighlightRole::error
}),
);
if target_is_valid && self.io_still_ok() && self.file_tester.test_path(&target, false) {
for i in redir.target.source_range().as_usize() {
self.color_array[i].valid_path = true;
}
}
}
fn visit_variable_assignment(&mut self, varas: &VariableAssignment) {
@@ -1392,6 +1397,9 @@ macro_rules! validate {
let mut param_valid_path = HighlightSpec::with_fg(HighlightRole::param);
param_valid_path.valid_path = true;
let mut redirection_valid_path = HighlightSpec::with_fg(HighlightRole::redirection);
redirection_valid_path.valid_path = true;
let saved_flag = future_feature_flags::test(FeatureFlag::AmpersandNoBgInToken);
future_feature_flags::set(FeatureFlag::AmpersandNoBgInToken, true);
let _restore_saved_flag = ScopeGuard::new((), |_| {
@@ -1529,7 +1537,7 @@ macro_rules! validate {
("param1", fg(HighlightRole::param)),
// Input redirection.
("<", fg(HighlightRole::redirection)),
("/bin/echo", fg(HighlightRole::redirection)),
("/dev/null", redirection_valid_path),
// Output redirection to a valid fd.
("1>&2", fg(HighlightRole::redirection)),
// Output redirection to an invalid fd.