Skip to content

Commit 94924db

Browse files
Support "Copy Path" operation in WSL (#2413)
1 parent 8db448c commit 94924db

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
* Set `CREATE_NO_WINDOW` flag when executing Git hooks on Windows ([#2371](https://github.com/extrawurst/gitui/pull/2371))
1616

1717
### Added
18+
* support for "Copy Path" action in WSL [[@johnDeSilencio](https://github.com/johnDeSilencio)] ([#2413](https://github.com/extrawurst/gitui/pull/2413))
1819
* help popup scrollbar [[@wugeer](https://github.com/wugeer)](https://github.com/extrawurst/gitui/pull/2388))
1920
* add popups for viewing, adding, updating and removing remotes [[@robin-thoene](https://github.com/robin-thoene)] ([#2172](https://github.com/extrawurst/gitui/issues/2172))
2021

src/clipboard.rs

+18
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,30 @@ fn exec_copy_with_args(
4949
}
5050
}
5151

52+
// Implementation taken from https://crates.io/crates/wsl.
53+
// Using /proc/sys/kernel/osrelease as an authoratative source
54+
// based on this comment: https://github.com/microsoft/WSL/issues/423#issuecomment-221627364
55+
#[cfg(all(target_family = "unix", not(target_os = "macos")))]
56+
fn is_wsl() -> bool {
57+
if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease") {
58+
if let Ok(s) = std::str::from_utf8(&b) {
59+
let a = s.to_ascii_lowercase();
60+
return a.contains("microsoft") || a.contains("wsl");
61+
}
62+
}
63+
false
64+
}
65+
5266
#[cfg(all(target_family = "unix", not(target_os = "macos")))]
5367
pub fn copy_string(text: &str) -> Result<()> {
5468
if std::env::var("WAYLAND_DISPLAY").is_ok() {
5569
return exec_copy_with_args("wl-copy", &[], text, false);
5670
}
5771

72+
if is_wsl() {
73+
return exec_copy_with_args("clip.exe", &[], text, false);
74+
}
75+
5876
if exec_copy_with_args(
5977
"xclip",
6078
&["-selection", "clipboard"],

0 commit comments

Comments
 (0)