diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-02 01:16:21 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-02 01:16:21 +0300 |
| commit | a9111cbab2a7550c7e84ec94c8b388de9a44daa3 (patch) | |
| tree | ed60b5baf7fd5d138aa5ab7d7d1b8892d3f41b73 /src/platform/macos.rs | |
| parent | 6a5b431e39c3a77652dc22e692925027cb69b965 (diff) | |
fix: open scrollback editor on windows without sh
refs #914
Diffstat (limited to 'src/platform/macos.rs')
| -rw-r--r-- | src/platform/macos.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/platform/macos.rs b/src/platform/macos.rs index df957652..3770a3be 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -16,6 +16,30 @@ const PROC_PGRP_ONLY: u32 = 2; const SERVER_NOFILE_LIMIT_TARGET: libc::rlim_t = 8192; const CF_STRING_ENCODING_UTF8: u32 = 0x0800_0100; +pub(crate) fn scrollback_editor_argv(path: &Path) -> std::io::Result<Vec<String>> { + let quoted_path = shell_quote(&path.display().to_string()); + let command = format!( + r#"scrollback_file={quoted_path}; eval "${{EDITOR:-vi}} \"\$scrollback_file\""; status=$?; rm -f "$scrollback_file"; exit $status"# + ); + Ok(vec!["/bin/sh".to_string(), "-c".to_string(), command]) +} + +fn shell_quote(value: &str) -> String { + if !value.is_empty() + && value.chars().all(|ch| { + ch.is_ascii_alphanumeric() + || matches!( + ch, + '@' | '%' | '_' | '+' | '=' | ':' | ',' | '.' | '/' | '-' + ) + }) + { + return value.to_string(); + } + + format!("'{}'", value.replace('\'', "'\\''")) +} + #[repr(C)] struct TisInputSource { _private: [u8; 0], @@ -1117,4 +1141,15 @@ printf '%s\n' "$@" > "$HERDR_NOTIFY_ARGS" "-e\non run argv\n-e\ndisplay notification (item 2 of argv) with title (item 1 of argv)\n-e\nend run\ntitle\nbody\n" ); } + + #[test] + fn scrollback_editor_argv_preserves_unix_editor_shell_semantics() { + let path = std::path::Path::new("/tmp/herdr scrollback.txt"); + let argv = scrollback_editor_argv(path).unwrap(); + + assert_eq!(argv[0], "/bin/sh"); + assert_eq!(argv[1], "-c"); + assert!(argv[2].contains("EDITOR:-vi")); + assert!(argv[2].contains("/tmp/herdr scrollback.txt")); + } } |
