Compare commits
1 Commits
master
...
plugins-ap
Author | SHA1 | Date | |
---|---|---|---|
f9ef5665fe
|
@ -15,7 +15,13 @@ Simply search for the application you wish to launch.
|
|||||||
Config(
|
Config(
|
||||||
// Also show the Desktop Actions defined in the desktop files, e.g. "New Window" from LibreWolf
|
// Also show the Desktop Actions defined in the desktop files, e.g. "New Window" from LibreWolf
|
||||||
desktop_actions: true,
|
desktop_actions: true,
|
||||||
max_entries: 5,
|
|
||||||
|
max_entries: 5,
|
||||||
|
|
||||||
|
// A command to preprocess the command from the desktop file. The commands should take arguments in this order:
|
||||||
|
// command_name <term|no-term> <command>
|
||||||
|
preprocess_exec_script: Some("/home/user/.local/share/anyrun/preprocess_application_command.sh")
|
||||||
|
|
||||||
// The terminal used for running terminal based desktop entries, if left as `None` a static list of terminals is used
|
// The terminal used for running terminal based desktop entries, if left as `None` a static list of terminals is used
|
||||||
// to determine what terminal to use.
|
// to determine what terminal to use.
|
||||||
terminal: Some("alacritty"),
|
terminal: Some("alacritty"),
|
||||||
|
@ -3,12 +3,13 @@ use anyrun_plugin::{anyrun_interface::HandleResult, *};
|
|||||||
use fuzzy_matcher::FuzzyMatcher;
|
use fuzzy_matcher::FuzzyMatcher;
|
||||||
use scrubber::DesktopEntry;
|
use scrubber::DesktopEntry;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{env, fs, process::Command};
|
use std::{env, fs, path::PathBuf, process::Command};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
desktop_actions: bool,
|
desktop_actions: bool,
|
||||||
max_entries: usize,
|
max_entries: usize,
|
||||||
|
preprocess_exec_script: Option<PathBuf>,
|
||||||
terminal: Option<String>,
|
terminal: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ impl Default for Config {
|
|||||||
Self {
|
Self {
|
||||||
desktop_actions: false,
|
desktop_actions: false,
|
||||||
max_entries: 5,
|
max_entries: 5,
|
||||||
|
preprocess_exec_script: None,
|
||||||
terminal: None,
|
terminal: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,21 +47,36 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let exec = if let Some(script) = &state.config.preprocess_exec_script {
|
||||||
|
let output = Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg(format!(
|
||||||
|
"{} {} {}",
|
||||||
|
script.display(),
|
||||||
|
if entry.term { "term" } else { "no-term" },
|
||||||
|
&entry.exec
|
||||||
|
))
|
||||||
|
.output()
|
||||||
|
.unwrap_or_else(|why| {
|
||||||
|
eprintln!("Error running preprocess script: {}", why);
|
||||||
|
std::process::exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
String::from_utf8_lossy(&output.stdout).trim().to_string()
|
||||||
|
} else {
|
||||||
|
entry.exec.clone()
|
||||||
|
};
|
||||||
|
|
||||||
if entry.term {
|
if entry.term {
|
||||||
match &state.config.terminal {
|
match &state.config.terminal {
|
||||||
Some(term) => {
|
Some(term) => {
|
||||||
if let Err(why) = Command::new(term).arg("-e").arg(&entry.exec).spawn() {
|
if let Err(why) = Command::new(term).arg("-e").arg(&exec).spawn() {
|
||||||
eprintln!("Error running desktop entry: {}", why);
|
eprintln!("Error running desktop entry: {}", why);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
for term in SENSIBLE_TERMINALS {
|
for term in SENSIBLE_TERMINALS {
|
||||||
if Command::new(term)
|
if Command::new(term).arg("-e").arg(&exec).spawn().is_ok() {
|
||||||
.arg("-e")
|
|
||||||
.arg(&entry.exec)
|
|
||||||
.spawn()
|
|
||||||
.is_ok()
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,7 +87,7 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
|
|||||||
|
|
||||||
Command::new("sh")
|
Command::new("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(&entry.exec)
|
.arg(&exec)
|
||||||
.current_dir(if let Some(path) = &entry.path {
|
.current_dir(if let Some(path) = &entry.path {
|
||||||
if path.exists() { path } else { current_dir }
|
if path.exists() { path } else { current_dir }
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user