fish: add patch to fix kitty build

This commit is contained in:
r-vdp
2025-03-03 13:26:13 +01:00
parent 98ca712b8a
commit 248b27a56b
3 changed files with 146 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
commit 1a219776a9a9487828a6cb3f2b9581afb308d4fb
Author: Johannes Altmanninger <aclopte@gmail.com>
Date: Mon Mar 3 10:37:49 2025 +0100
Add the commandline to the OSC 133 command start
Given
$ cat ~/.config/kitty/kitty.conf
notify_on_cmd_finish unfocused 0.1 command notify-send "job finished with status: %s" %c
kitty will send a notification whenever a long-running (>.1s) foreground
command finishes while kitty is not focused.
The %c placeholder will be replaced by the commandline.
This is passed via the OSC 133 command start marker, kitty's fish shell
integration.
That integration has been disabled for fish 4.0.0 because it's no longer
necessary since fish already prints OSC 133. But we missed the parameter for
the command string. Fix it. (It's debatable whether the shell or the terminal
should provide this feature but I think we should fix this regression?)
Closes #11203
See https://github.com/kovidgoyal/kitty/issues/8385#issuecomment-2692659161
(cherry picked from commit 4378e73fc746b539c851c22800b42fdfeb1a1964)
diff --git a/src/reader.rs b/src/reader.rs
index 46f68d8c4..5f68ac57d 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -88,6 +88,7 @@ use crate::libc::MB_CUR_MAX;
use crate::nix::isatty;
use crate::operation_context::{get_bg_context, OperationContext};
use crate::output::parse_color;
+use crate::output::BufferedOuputter;
use crate::output::Outputter;
use crate::pager::{PageRendering, Pager, SelectionMotion};
use crate::panic::AT_EXIT;
@@ -650,8 +651,13 @@ fn read_i(parser: &Parser) -> i32 {
data.command_line.clear();
data.update_buff_pos(EditableLineTag::Commandline, None);
data.command_line_changed(EditableLineTag::Commandline);
- // OSC 133 End of command
- data.screen.write_bytes(b"\x1b]133;C\x07");
+ // OSC 133 "Command start"
+ write!(
+ BufferedOuputter::new(&mut Outputter::stdoutput().borrow_mut()),
+ "\x1b]133;C;cmdline_url={}\x07",
+ escape_string(&command, EscapeStringStyle::Url),
+ )
+ .unwrap();
event::fire_generic(parser, L!("fish_preexec").to_owned(), vec![command.clone()]);
let eval_res = reader_run_command(parser, &command);
signal_clear_cancel();

View File

@@ -187,6 +187,12 @@ stdenv.mkDerivation (finalAttrs: {
# * <https://github.com/LnL7/nix-darwin/issues/122>
# * <https://github.com/fish-shell/fish-shell/issues/7142>
./nix-darwin-path.patch
# Fixes a build issue in kitty, see https://github.com/fish-shell/fish-shell/commit/97f0809b62a1fa77df1b9fcbbfe623b6187b5013
# The first patch is needed since it introduces the BufferedOutputter type that's
# used by the second one.
./reduce_writes.patch
./osc_133.patch
];
# Fix FHS paths in tests

View File

@@ -0,0 +1,82 @@
commit 780541aa2509e6020ffbb6359e412c66eeca03dd
Author: Johannes Altmanninger <aclopte@gmail.com>
Date: Mon Mar 3 10:37:49 2025 +0100
Try to reduce write(3) calls for OSC 133 prompt markers
Something like
write!(f, "foo{}bar", ...)
seems to call f.write_str() thrice.
Splitting a single OSC 133 command into three calls to write(3) might result in
odd situations if one of them fails. Let's try to do it in one in most cases.
Add a new buffered output type that can be used with write!(). This is
somewhat redundant given that we have scoped_buffer(). While at it, remove
the confused error handling. This doesn't fail unless we are OOM (and this
new type makes that more obvious).
(cherry picked from commit e5e932e97082ce9079a8d6e665839c5bfd875049)
diff --git a/src/output.rs b/src/output.rs
index 8833df4a0..eeb3be0a7 100644
--- a/src/output.rs
+++ b/src/output.rs
@@ -456,6 +456,35 @@ impl Outputter {
}
}
+pub struct BufferedOuputter<'a>(&'a mut Outputter);
+
+impl<'a> BufferedOuputter<'a> {
+ pub fn new(outputter: &'a mut Outputter) -> Self {
+ outputter.begin_buffering();
+ Self(outputter)
+ }
+}
+
+impl<'a> Drop for BufferedOuputter<'a> {
+ fn drop(&mut self) {
+ self.0.end_buffering();
+ }
+}
+
+impl<'a> Write for BufferedOuputter<'a> {
+ fn write(&mut self, buf: &[u8]) -> Result<usize> {
+ self.0
+ .write(buf)
+ .expect("Writing to in-memory buffer should never fail");
+ Ok(buf.len())
+ }
+
+ fn flush(&mut self) -> Result<()> {
+ self.0.flush().unwrap();
+ Ok(())
+ }
+}
+
/// Given a list of RgbColor, pick the "best" one, as determined by the color support. Returns
/// RgbColor::NONE if empty.
pub fn best_color(candidates: &[RgbColor], support: ColorSupport) -> RgbColor {
diff --git a/src/reader.rs b/src/reader.rs
index ea8e4356c..46f68d8c4 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -664,11 +664,12 @@ fn read_i(parser: &Parser) -> i32 {
parser.libdata_mut().exit_current_script = false;
// OSC 133 "Command finished"
- let _ = write!(
- Outputter::stdoutput().borrow_mut(),
+ write!(
+ BufferedOuputter::new(&mut Outputter::stdoutput().borrow_mut()),
"\x1b]133;D;{}\x07",
parser.get_last_status()
- );
+ )
+ .unwrap();
event::fire_generic(parser, L!("fish_postexec").to_owned(), vec![command]);
// Allow any pending history items to be returned in the history array.
data.history.resolve_pending();