summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Dilly <dilly.stephan@gmail.com>2020-10-11 00:23:20 +0200
committerGitHub <noreply@github.com>2020-10-11 00:23:20 +0200
commit0b97c545eda4eda450d670609d7f9cfbc0f9502e (patch)
tree895605fb01d82824b6e6c4bbe6b6f8c759cf3eed
parent62573b9d7a564d21ef8b7c1852ade2c46e0fe14e (diff)
cleanup clipboard and add to changelog (#325)
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/clipboard.rs20
2 files changed, 10 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca881d43..cf8e0c54 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- do not highlight selection in diff view when not focused ([#270](https://github.com/extrawurst/gitui/issues/270))
+- copy to clipboard using `xclip`(linux), `pbcopy`(mac) or `clip`(win) [[@cruessler](https://github.com/cruessler)] ([#262](https://github.com/extrawurst/gitui/issues/262))
- compact treeview [[@WizardOhio24](https://github.com/WizardOhio24)] ([#192](https://github.com/extrawurst/gitui/issues/192))
![tree](assets/compact-tree.png)
diff --git a/src/clipboard.rs b/src/clipboard.rs
index 11bd04ef..6730ceb1 100644
--- a/src/clipboard.rs
+++ b/src/clipboard.rs
@@ -2,12 +2,11 @@ use anyhow::Result;
use std::io::Write;
use std::process::{Command, Stdio};
-fn execute_copy_command(
- command: &mut Command,
- string: &str,
-) -> Result<()> {
+fn execute_copy_command(command: Command, text: &str) -> Result<()> {
use anyhow::anyhow;
+ let mut command = command;
+
let mut process = command
.stdin(Stdio::piped())
.stdout(Stdio::null())
@@ -18,7 +17,7 @@ fn execute_copy_command(
.stdin
.as_mut()
.ok_or_else(|| anyhow!("`{:?}`", command))?
- .write_all(string.as_bytes())
+ .write_all(text.as_bytes())
.map_err(|e| anyhow!("`{:?}`: {}", command, e))?;
process
@@ -30,18 +29,17 @@ fn execute_copy_command(
#[cfg(target_os = "linux")]
pub fn copy_string(string: &str) -> Result<()> {
- execute_copy_command(
- Command::new("xclip").arg("-selection").arg("clipboard"),
- string,
- )
+ let mut cmd = Command::new("xclip");
+ cmd.arg("-selection").arg("clipboard");
+ execute_copy_command(cmd, string)
}
#[cfg(target_os = "macos")]
pub fn copy_string(string: &str) -> Result<()> {
- execute_copy_command(&mut Command::new("pbcopy"), string)
+ execute_copy_command(Command::new("pbcopy"), string)
}
#[cfg(windows)]
pub fn copy_string(string: &str) -> Result<()> {
- execute_copy_command(&mut Command::new("clip"), string)
+ execute_copy_command(Command::new("clip"), string)
}