mirror of
https://github.com/kittywitch/fzfdapter.git
synced 2026-02-09 06:39:19 -08:00
feat: fork instead of just spawning command
This commit is contained in:
parent
ce503517bb
commit
17aab3c2d7
4 changed files with 39 additions and 25 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -164,6 +164,15 @@ version = "0.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
|
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fork"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed479091df6b84e9670acc5fa0339f1d2c6b7459e432455a26c75848048ae14d"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "freedesktop-desktop-entry"
|
name = "freedesktop-desktop-entry"
|
||||||
version = "0.7.19"
|
version = "0.7.19"
|
||||||
|
|
@ -185,6 +194,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
|
"fork",
|
||||||
"freedesktop-desktop-entry",
|
"freedesktop-desktop-entry",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"is_executable",
|
"is_executable",
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ edition = "2024"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.100"
|
anyhow = "1.0.100"
|
||||||
clap = { version = "4.5.50", features = ["derive"] }
|
clap = { version = "4.5.50", features = ["derive"] }
|
||||||
|
fork = "0.3.1"
|
||||||
freedesktop-desktop-entry = "0.7.19"
|
freedesktop-desktop-entry = "0.7.19"
|
||||||
indexmap = { version = "2.12.0", features = ["serde"] }
|
indexmap = { version = "2.12.0", features = ["serde"] }
|
||||||
is_executable = "1.0.5"
|
is_executable = "1.0.5"
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,10 @@ rustPlatform.buildRustPackage (_finalAttrs: {
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
cargoHash = "sha256-aaLgttzAlHJciCDn9vQ2bHPoNc6lcXQa4GIJQPvUgyw=";
|
cargoHash = "sha256-gwaH/Q9VN1i3JLruj6aRBhInWy+qHV+g32wSKY++msw=";
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
|
mainProgram = "fzfdapter";
|
||||||
description = "fzfdapter, a fuzzel/wofi/rofi... thing for your terminal";
|
description = "fzfdapter, a fuzzel/wofi/rofi... thing for your terminal";
|
||||||
homepage = "https://github.com/kittywitch/fzfdapter";
|
homepage = "https://github.com/kittywitch/fzfdapter";
|
||||||
license = lib.licenses.gpl3;
|
license = lib.licenses.gpl3;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
use {
|
use {
|
||||||
crate::config::AdapterConfig,
|
crate::config::AdapterConfig, anyhow::anyhow, fork::{daemon, Fork}, std::{
|
||||||
anyhow::anyhow,
|
|
||||||
std::{
|
|
||||||
mem,
|
mem,
|
||||||
path::Path,
|
path::Path,
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
@ -18,15 +16,17 @@ pub(crate) enum WhatDo {
|
||||||
|
|
||||||
pub(crate) fn handle_xdg(exec: Vec<String>) -> anyhow::Result<()> {
|
pub(crate) fn handle_xdg(exec: Vec<String>) -> anyhow::Result<()> {
|
||||||
let args = exec.get(1..).unwrap_or_default();
|
let args = exec.get(1..).unwrap_or_default();
|
||||||
let exec_run = Command::new(exec.first().ok_or(anyhow!(
|
if let Ok(Fork::Child) = daemon(false, false) {
|
||||||
"Command not provided within the XDG desktop file correctly?"
|
let exec_run = Command::new(exec.first().ok_or(anyhow!(
|
||||||
))?)
|
"Command not provided within the XDG desktop file correctly?"
|
||||||
.args(args)
|
))?)
|
||||||
.stdout(Stdio::null())
|
.args(args)
|
||||||
.stdin(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.spawn()?;
|
.stderr(Stdio::null())
|
||||||
mem::forget(exec_run);
|
.spawn()?;
|
||||||
|
mem::forget(exec_run);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,16 +34,18 @@ pub(crate) fn handle_terminal(config: &AdapterConfig, args: &[&str]) -> anyhow::
|
||||||
let mut in_args = args.iter().map(|x| x.to_string()).collect();
|
let mut in_args = args.iter().map(|x| x.to_string()).collect();
|
||||||
let mut term_args = config.terminal_args();
|
let mut term_args = config.terminal_args();
|
||||||
term_args.append(&mut in_args);
|
term_args.append(&mut in_args);
|
||||||
let term_run = Command::new(
|
if let Ok(Fork::Child) = daemon(false, false) {
|
||||||
config
|
let term_run = Command::new(
|
||||||
.terminal_bin()
|
config
|
||||||
.ok_or(anyhow!("No defined or available terminal"))?,
|
.terminal_bin()
|
||||||
)
|
.ok_or(anyhow!("No defined or available terminal"))?,
|
||||||
.args(term_args)
|
)
|
||||||
.stdout(Stdio::null())
|
.args(term_args)
|
||||||
.stdin(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.spawn()?;
|
.stderr(Stdio::null())
|
||||||
mem::forget(term_run);
|
.spawn()?;
|
||||||
|
mem::forget(term_run);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue