termin is a lightweight Rust library designed to detect installed terminal emulators and execute commands within them. It is specifically tailored for CachyOS (Arch Linux) to ensure seamless integration with the distribution's preferred environment.
- Auto-Detection: Scans the system for available terminals based on a predefined priority list (Alacritty, Foot, Konsole, etc.).
- Smart Execution: Handles terminal-specific flags (e.g.,
-e,--wait) automatically. - Privilege Escalation: Built-in support for
pkexecto run commands as root. - Environment Aware: Respects the
$TERMINALenvironment variable.
Add termin to your Cargo.toml:
[dependencies]
termin = { git = "[https://github.com/pinpinroku/termin](https://github.com/pinpinroku/termin)" }
The simplest way to run a command in the user's preferred terminal:
use termin;
fn main() {
// Run a system update in a new terminal window
let success = termin::run_command("pacman -Syu", true);
if !success {
eprintln!("Could not find a supported terminal emulator.");
}
}If you need more control over the detection logic:
use termin::Terminal;
fn main() {
// 1. Detection based on priority list
let term = termin::get().expect("No terminal found");
// 2. Build a custom command
let cmd = term.build_cmd("echo 'Hello CachyOS!'", false);
// 3. Spawn the process
term.spawn(cmd).unwrap();
}termin searches for terminals in the following order to match the CachyOS experience:
- Alacritty (Performance)
- Foot (Wayland optimized)
- Konsole (KDE default)
- Kgx (Modern GNOME)
- ...and many more (Xfce4, Kitty, Ghostty, etc.)
Contributions are welcome! If you want to add support for a new terminal:
- Open an issue with the binary name and spawn flags.
- Or submit a Pull Request by adding a new variant to the
Terminalenum.
Please see the documentation for more technical details.
This project is licensed under the GPL-3.0-only. See the LICENSE file for details.