Users of kitty terminal emulator can
select any text in kitty and pass that text as an argument to any program
with a keyboard shortcut in kitty.conf
:
map kitty_mod+alt+w pass_selection_to_program wiki
I.e. hitting kitty_mod+alt+w
keyboard shortcut invokes wiki
shown below
with the selected text as argument:
#!/bin/sh
sr -t wikipedia "$@";;
wiki
displays wikipedia entry about the selected data (using surfraw(1), sr
).
However this usage pattern demands users to create and to memorize
more keyboard shortcuts for different programs to take advantage of
kitty's pass_selection_to_program
feature.
Mario extends kitty's pass_selection_to_program
feature:
- user selects text with a left-click
- user can hit either 'appliction menu' key on keyboard or click on a thumb button of the mouse to get a menu of programs
- user makes a choice from the menu (with either mouse or keyboard)
- the chosen program runs on the selected text
- Install rofi menu system
- Install xbindkeys to map mouse buttons to a keyboard key
- Copy
mario
to anywhere in$PATH
(and don't forget tochmod +x mario
); - Copy
.mario.menu
to$HOME
and edit it to suit your needs. - Configure
xbindkeys
and kitty. In this example we use 'application menu' to invoke the menu:
xbindkeys:
"xvkbd -text '\[Menu]'"
m:0x0 + b:9 (mouse)
"xvkbd -text '\[Menu]'"
m:0x0 + b:8 (mouse)
kitty:
# application menu showkey -a: ^[[29~ glfw key:348 native_code:0xff67
map 0xff67 pass_selection_to_program mario
- Add
xbindkeys
to initialization file of desktop session. - Change 'application Menu' and thumb buttons (8/9) of mouse to something else as you see fit.
For example, wiki
above can be rewritten as
#!/bin/sh
if [ -t 0 ]; then
sr -t wikipedia "$@";
else
kitty @ launch --no-response sr -t wikipedia "$@";
fi
wiki
opens a new window and displays result there when it is run from mario
i.e. non-interactively. When wiki
is run from a usual kitty window,
it displays the result in the window.
See rofi's documentation for more details.