diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2c99ca93c..226e7f9a2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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. diff --git a/src/highlight/highlight.rs b/src/highlight/highlight.rs index 76e8027c8..0d0aa72f4 100644 --- a/src/highlight/highlight.rs +++ b/src/highlight/highlight.rs @@ -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.