diff --git a/CHANGELOG.md b/CHANGELOG.md index 59b1710c..dda15f11 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)) diff --git a/src/clipboard.rs b/src/clipboard.rs index bf961d20..649f285a 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -49,12 +49,30 @@ 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() { 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"],