Compare commits
1 Commits
master
...
plugins-ap
| Author | SHA1 | Date | |
|---|---|---|---|
|
f9ef5665fe
|
@@ -173,8 +173,8 @@ Make sure all of the dependencies are installed, and then run the following
|
||||
commands in order:
|
||||
|
||||
```bash
|
||||
# Clone the repository and move to the cloned location
|
||||
git clone https://github.com/anyrun-org/anyrun && cd anyrun
|
||||
# Clone the repository and move to the cloned location
|
||||
git clone https://github.com/Kirottu/anyrun.git && cd anyrun
|
||||
|
||||
# Build all packages, and install the Anyrun binary
|
||||
cargo build --release
|
||||
@@ -287,7 +287,7 @@ plugin:
|
||||
crate-type = ["cdylib"] # Required to build a dynamic library that can be loaded by anyrun
|
||||
|
||||
[dependencies]
|
||||
anyrun-plugin = { git = "https://github.com/anyrun-org/anyrun" }
|
||||
anyrun-plugin = { git = "https://github.com/Kirottu/anyrun" }
|
||||
abi_stable = "0.11.1"
|
||||
# Any other dependencies you may have
|
||||
```
|
||||
|
||||
@@ -565,7 +565,7 @@ fn activate(app: >k::Application, runtime_data: Rc<RefCell<RuntimeData>>) {
|
||||
Inhibit(true)
|
||||
}
|
||||
// Handle when the selected match is "activated"
|
||||
constants::Return | constants::KP_Enter => {
|
||||
constants::Return => {
|
||||
let mut _runtime_data_clone = runtime_data_clone.borrow_mut();
|
||||
|
||||
let (selected_match, plugin_view) = match _runtime_data_clone
|
||||
|
||||
@@ -81,7 +81,7 @@ in
|
||||
|
||||
meta = {
|
||||
description = "A wayland native, highly customizable runner.";
|
||||
homepage = "https://github.com/anyrun-org/anyrun";
|
||||
homepage = "https://github.com/Kirottu/anyrun";
|
||||
license = [lib.licenses.gpl3];
|
||||
mainProgram = "anyrun";
|
||||
maintainers = with lib.maintainers; [NotAShelf n3oney];
|
||||
|
||||
@@ -65,7 +65,7 @@ in
|
||||
|
||||
meta = {
|
||||
description = "The ${name} plugin for Anyrun";
|
||||
homepage = "https://github.com/anyrun-org/anyrun";
|
||||
homepage = "https://github.com/Kirottu/anyrun";
|
||||
license = [lib.licenses.gpl3];
|
||||
maintainers = with lib.maintainers; [NotAShelf n3oney];
|
||||
};
|
||||
|
||||
@@ -15,15 +15,15 @@ Simply search for the application you wish to launch.
|
||||
Config(
|
||||
// Also show the Desktop Actions defined in the desktop files, e.g. "New Window" from LibreWolf
|
||||
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
|
||||
// to determine what terminal to use.
|
||||
terminal: Some(Terminal(
|
||||
// The main terminal command
|
||||
command: "alacritty",
|
||||
// What arguments should be passed to the terminal process to run the command correctly
|
||||
// {} is replaced with the command in the desktop entry
|
||||
args: "-e {}",
|
||||
)),
|
||||
terminal: Some("alacritty"),
|
||||
)
|
||||
```
|
||||
```
|
||||
@@ -3,19 +3,14 @@ use anyrun_plugin::{anyrun_interface::HandleResult, *};
|
||||
use fuzzy_matcher::FuzzyMatcher;
|
||||
use scrubber::DesktopEntry;
|
||||
use serde::Deserialize;
|
||||
use std::{env, fs, process::Command};
|
||||
use std::{env, fs, path::PathBuf, process::Command};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Config {
|
||||
desktop_actions: bool,
|
||||
max_entries: usize,
|
||||
terminal: Option<Terminal>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Terminal {
|
||||
command: String,
|
||||
args: String,
|
||||
preprocess_exec_script: Option<PathBuf>,
|
||||
terminal: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@@ -23,6 +18,7 @@ impl Default for Config {
|
||||
Self {
|
||||
desktop_actions: false,
|
||||
max_entries: 5,
|
||||
preprocess_exec_script: None,
|
||||
terminal: None,
|
||||
}
|
||||
}
|
||||
@@ -35,6 +31,8 @@ pub struct State {
|
||||
|
||||
mod scrubber;
|
||||
|
||||
const SENSIBLE_TERMINALS: &[&str] = &["alacritty", "foot", "kitty", "wezterm", "wterm"];
|
||||
|
||||
#[handler]
|
||||
pub fn handler(selection: Match, state: &State) -> HandleResult {
|
||||
let entry = state
|
||||
@@ -49,61 +47,36 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
|
||||
})
|
||||
.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 {
|
||||
match &state.config.terminal {
|
||||
Some(term) => {
|
||||
if let Err(why) = Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(format!(
|
||||
"{} {}",
|
||||
term.command,
|
||||
term.args.replace("{}", &entry.exec)
|
||||
))
|
||||
.spawn()
|
||||
{
|
||||
if let Err(why) = Command::new(term).arg("-e").arg(&exec).spawn() {
|
||||
eprintln!("Error running desktop entry: {}", why);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let sensible_terminals = &[
|
||||
Terminal {
|
||||
command: "alacritty".to_string(),
|
||||
args: "-e {}".to_string(),
|
||||
},
|
||||
Terminal {
|
||||
command: "foot".to_string(),
|
||||
args: "-e \"{}\"".to_string(),
|
||||
},
|
||||
Terminal {
|
||||
command: "kitty".to_string(),
|
||||
args: "-e \"{}\"".to_string(),
|
||||
},
|
||||
Terminal {
|
||||
command: "wezterm".to_string(),
|
||||
args: "-e \"{}\"".to_string(),
|
||||
},
|
||||
Terminal {
|
||||
command: "wterm".to_string(),
|
||||
args: "-e \"{}\"".to_string(),
|
||||
},
|
||||
];
|
||||
for term in sensible_terminals {
|
||||
if Command::new("which")
|
||||
.arg(&term.command)
|
||||
.output()
|
||||
.is_ok_and(|output| output.status.success())
|
||||
{
|
||||
if let Err(why) = Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(format!(
|
||||
"{} {}",
|
||||
term.command,
|
||||
term.args.replace("{}", &entry.exec)
|
||||
))
|
||||
.spawn()
|
||||
{
|
||||
eprintln!("Error running desktop entry: {}", why);
|
||||
}
|
||||
for term in SENSIBLE_TERMINALS {
|
||||
if Command::new(term).arg("-e").arg(&exec).spawn().is_ok() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -114,18 +87,15 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
|
||||
|
||||
Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(&entry.exec)
|
||||
.arg(&exec)
|
||||
.current_dir(if let Some(path) = &entry.path {
|
||||
if path.exists() {
|
||||
path
|
||||
} else {
|
||||
current_dir
|
||||
}
|
||||
if path.exists() { path } else { current_dir }
|
||||
} else {
|
||||
current_dir
|
||||
})
|
||||
.spawn()
|
||||
} {
|
||||
}
|
||||
{
|
||||
eprintln!("Error running desktop entry: {}", why);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,15 +7,3 @@ Allows for easy integration into scripts that have been made with something like
|
||||
|
||||
This plugin should generally be used alone, if a dmenu replacement is needed. This can be done with `anyrun --plugins libstdin.so`.
|
||||
The content to fuzzy match on needs to be piped into Anyrun.
|
||||
|
||||
## Configuration
|
||||
|
||||
```ron
|
||||
Config(
|
||||
// Whether to allow the user to input any arbitrary text besides the options provided
|
||||
allow_invalid: false,
|
||||
// How many entries should be displayed at max
|
||||
max_entries: 5,
|
||||
)
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user