From 3ce8180d215cc7e99f86acc21ee24ff9e0414d4c Mon Sep 17 00:00:00 2001 From: "Robert (GaimsDevSoftware)" <285959242+GaimsDevSoftware@users.noreply.github.com> Date: Mon, 29 Jun 2026 01:43:28 +0200 Subject: [PATCH] Add "Run in terminal" plugin for COMMAND selections; support ptyxis ContentType.COMMAND was defined and classified (e.g. shell-command-looking selections like `wpctl set-volume @DEFAULT_AUDIO_SINK@ 50%`) but no plugin registered for it, so the popup never offered a way to act on it. - plugins_repo/run_in_terminal.py: new plugin registering a "Run in terminal" button (icon utilities-terminal-symbolic, priority 30) for ContentType.COMMAND only. The handler defers to the existing actions.run_in_terminal backend (terminal discovery, confirmation dialog gated on terminal_confirm_run, echo-wrap, keep-open via terminal_keep_open, safe argv spawn). - actions.py: add ptyxis as the first entry in _TERMINALS. Ptyxis is the default terminal on Fedora 41+ / modern GNOME and uses the same `-- bash -c ` convention as gnome-terminal. Without it _find_terminal() returned None on a stock GNOME box where ptyxis is the only terminal installed, so run_in_terminal silently no-op'd. Live-tested on Fedora 44 GNOME/Wayland: a real ptyxis window opens, the confirmation dialog appears, and the command runs after pressing Run. --- actions.py | 4 ++++ plugins_repo/run_in_terminal.py | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 plugins_repo/run_in_terminal.py diff --git a/actions.py b/actions.py index b9ade24..fc1e59f 100644 --- a/actions.py +++ b/actions.py @@ -265,6 +265,10 @@ def _in_flatpak() -> bool: _TERMINALS = [ + # Ptyxis is the default terminal on Fedora 41+ / modern GNOME. Same + # `-- bash -c ` convention as gnome-terminal. Listed first so it + # wins on GNOME boxes where it's the only terminal installed. + ("ptyxis", ["ptyxis", "--", "bash", "-c"]), ("gnome-terminal", ["gnome-terminal", "--", "bash", "-c"]), ("konsole", ["konsole", "-e", "bash", "-c"]), ("xfce4-terminal", ["xfce4-terminal", "-e"]), diff --git a/plugins_repo/run_in_terminal.py b/plugins_repo/run_in_terminal.py new file mode 100644 index 0000000..8aaff22 --- /dev/null +++ b/plugins_repo/run_in_terminal.py @@ -0,0 +1,38 @@ +"""Run a selected shell command in a terminal. + +The classifier tags shell-command-looking selections as +``ContentType.COMMAND`` (e.g. ``wpctl set-volume @DEFAULT_AUDIO_SINK@ 50%``), +but nothing acted on them - this plugin adds the missing "Run in terminal" +button for exactly that content type. + +The heavy lifting lives in ``actions.run_in_terminal``: it finds an available +terminal emulator, optionally shows a confirmation dialog +(``terminal_confirm_run``, default on), echoes the command, runs it, and keeps +the terminal open afterwards (``terminal_keep_open``, default on). Launch is +done with a real argv list (never ``shell=True`` at construction), and the +confirmation dialog is the guard against running a malicious-looking selection +by accident. +""" +from __future__ import annotations + +import actions +from classifier import ContentType +from plugin_base import Plugin + + +def _run(text: str) -> None: + actions.run_in_terminal(text) + + +def register(register_plugin) -> None: + register_plugin(Plugin( + name="run-in-terminal", + icon="utilities-terminal-symbolic", + tooltip="Run in terminal", + handler=_run, + content_types=(ContentType.COMMAND,), + # Lower than the transform/utility plugins so it sits toward the + # end of the bar - it's a deliberate, occasional action, not a + # first-reach one. + priority=30, + ))