Test message 123!
This commit is contained in:
1 parent
4cf726709f
commit
d4fdc9890a
52 files changed
+5537
-277
No files matched your search
@@ -0,0 +1,26 @@
|
||||
use std::io::Write as _;
|
||||
|
||||
/// Copy text using a configured command string (e.g. "wl-copy" or "xclip -selection clipboard").
|
||||
pub fn copy_to_clipboard(text: &str, cmd: &str) -> bool {
|
||||
if cmd.is_empty() { return false; }
|
||||
let parts: Vec<&str> = cmd.split_whitespace().collect();
|
||||
let (prog, args) = parts.split_first().unwrap_or((&"", &[]));
|
||||
let Ok(mut child) = std::process::Command::new(prog)
|
||||
.args(args)
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.spawn() else { return false; };
|
||||
if let Some(mut stdin) = child.stdin.take() { let _ = stdin.write_all(text.as_bytes()); }
|
||||
child.wait().map(|s| s.success()).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Copy text by auto-detecting the available clipboard tool (wl-copy or xclip).
|
||||
pub fn copy_auto(text: &str) -> bool {
|
||||
for (cmd, args) in [("wl-copy", &[][..]), ("xclip", &["-selection", "clipboard"][..])] {
|
||||
if let Ok(mut child) = std::process::Command::new(cmd)
|
||||
.args(args).stdin(std::process::Stdio::piped()).spawn() {
|
||||
if let Some(mut stdin) = child.stdin.take() { let _ = stdin.write_all(text.as_bytes()); }
|
||||
if child.wait().map(|s| s.success()).unwrap_or(false) { return true; }
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
pub fn git_run(path: &std::path::Path, args: &[&str]) {
|
||||
match std::process::Command::new("git").arg("-C").arg(path).args(args).status() {
|
||||
Ok(s) if s.success() => {}
|
||||
Ok(s) => eprintln!(" git {} → exit {}", args.join(" "), s),
|
||||
Err(e) => eprintln!(" git {}: {}", args.join(" "), e),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn git_run_ok(path: &std::path::Path, args: &[&str]) -> bool {
|
||||
std::process::Command::new("git").arg("-C").arg(path).args(args)
|
||||
.status().map(|s| s.success()).unwrap_or(false)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod clipboard;
|
||||
pub mod git;
|
||||
pub mod url;
|
||||
@@ -0,0 +1,9 @@
|
||||
pub fn to_web_url(git_url: &str) -> String {
|
||||
if git_url.starts_with("http") { return git_url.trim_end_matches(".git").to_string(); }
|
||||
if let Some(colon) = git_url.rfind(':') {
|
||||
let host = git_url[..colon].split('@').last().unwrap_or("");
|
||||
let path = git_url[colon + 1..].trim_end_matches(".git");
|
||||
return format!("https://{}/{}", host, path);
|
||||
}
|
||||
git_url.to_string()
|
||||
}
|
||||
Reference in new issue
Block a user