From c8c67a69e00884bb5fbec4870f854f5e03c635ed Mon Sep 17 00:00:00 2001 From: "Nicholas R. Smith" Date: Wed, 30 Oct 2024 18:38:24 -0700 Subject: [PATCH 1/4] feat(clipboard): add private utility function for detecting if we are running in WSL --- src/clipboard.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/clipboard.rs b/src/clipboard.rs index bf961d2065..f745d99270 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -49,6 +49,20 @@ fn exec_copy_with_args( } } +// Implementation taken from https://crates.io/crates/wsl. +// Using /proc/sys/kernel/osrelease as an authoratative source +// based on this comment: https://github.com/microsoft/WSL/issues/423#issuecomment-221627364 +#[cfg(all(target_family = "unix", not(target_os = "macos")))] +fn is_wsl() -> bool { + if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease") { + if let Ok(s) = std::str::from_utf8(&b) { + let a = s.to_ascii_lowercase(); + return a.contains("microsoft") || a.contains("wsl"); + } + } + false +} + #[cfg(all(target_family = "unix", not(target_os = "macos")))] pub fn copy_string(text: &str) -> Result<()> { if std::env::var("WAYLAND_DISPLAY").is_ok() { From 5ff904890ea3609a20dc2693c6b1217c04016a33 Mon Sep 17 00:00:00 2001 From: "Nicholas R. Smith" Date: Wed, 30 Oct 2024 18:39:46 -0700 Subject: [PATCH 2/4] feat(clipboard): use clip.exe for 'Copy Path' action if we are running in WSL --- src/clipboard.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/clipboard.rs b/src/clipboard.rs index f745d99270..df76d1dd06 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -69,6 +69,10 @@ pub fn copy_string(text: &str) -> Result<()> { return exec_copy_with_args("wl-copy", &[], text, false); } + if is_wsl() { + return exec_copy_with_args("clip.exe", &[], text, false); + } + if exec_copy_with_args( "xclip", &["-selection", "clipboard"], From 044e20cbcd072139839fbc21aeed342876f157af Mon Sep 17 00:00:00 2001 From: "Nicholas R. Smith" Date: Wed, 30 Oct 2024 18:48:56 -0700 Subject: [PATCH 3/4] style(clipboard): fix formatting --- src/clipboard.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/clipboard.rs b/src/clipboard.rs index df76d1dd06..649f285a0e 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -54,13 +54,13 @@ fn exec_copy_with_args( // based on this comment: https://github.com/microsoft/WSL/issues/423#issuecomment-221627364 #[cfg(all(target_family = "unix", not(target_os = "macos")))] fn is_wsl() -> bool { - if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease") { - if let Ok(s) = std::str::from_utf8(&b) { - let a = s.to_ascii_lowercase(); - return a.contains("microsoft") || a.contains("wsl"); - } - } - false + if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease") { + if let Ok(s) = std::str::from_utf8(&b) { + let a = s.to_ascii_lowercase(); + return a.contains("microsoft") || a.contains("wsl"); + } + } + false } #[cfg(all(target_family = "unix", not(target_os = "macos")))] From 16958f9fe78b17c5528fa532f4681d257eceb079 Mon Sep 17 00:00:00 2001 From: "Nicholas R. Smith" Date: Wed, 30 Oct 2024 20:14:24 -0700 Subject: [PATCH 4/4] chore(changelog): add bullet point for PR #2413 to 'Added' section --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59b1710c60..dda15f11f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Set `CREATE_NO_WINDOW` flag when executing Git hooks on Windows ([#2371](https://github.com/extrawurst/gitui/pull/2371)) ### Added +* support for "Copy Path" action in WSL [[@johnDeSilencio](https://github.com/johnDeSilencio)] ([#2413](https://github.com/extrawurst/gitui/pull/2413)) * help popup scrollbar [[@wugeer](https://github.com/wugeer)](https://github.com/extrawurst/gitui/pull/2388)) * add popups for viewing, adding, updating and removing remotes [[@robin-thoene](https://github.com/robin-thoene)] ([#2172](https://github.com/extrawurst/gitui/issues/2172))