diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bbeefbd14ea9..d8c7e43ebb0f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,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. diff --git a/src/highlight/highlight.rs b/src/highlight/highlight.rs index d80c9c9041c7..d627854693cc 100644 --- a/src/highlight/highlight.rs +++ b/src/highlight/highlight.rs @@ -969,6 +969,11 @@ impl<'s> Highlighter<'s> { 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) { @@ -1376,6 +1381,9 @@ mod tests { 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((), |_| { @@ -1513,7 +1521,7 @@ mod tests { ("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.