You are looking for a text snippet possibility, where typing a short text snippet expands to a phrase. A significant productivity booster indeed.
Your idea to do this by scripting is very valid. I run a homemade script myself based on snippy
.
Before moving to scripting, you may want to evaluate a few options. Caveat: all of these options do not work on the Wayland display manager, and for now, no alternatives seem available. If you are running a standard Ubuntu desktop, you need to switch to an X11 session or try scripting yourself using the experimental tools that simulate keyboard activity under Wayland (ydotool
, wtype
).
Espanso: https://espanso.org/docs/get-started/
Highly recommended to try. The setup is text based. It watches what you type, and a trigger, e.g. :asdf
will be replaced by your custom string. Some Wayland support already made it into the application.
Autokey: https://github.com/autokey/autokey
Venerable Autokey once failed on me, after which I moved to a script based solution. I did not try it after that. However, it appears to be back and properly maintained again. This is extensively controlled using a GUI. It can do exactly what you want, i.e., replace text as you type an abbreviation you defined such as asdf
.
texpander: https://github.com/leehblue/texpander
This is a bash script based solution, relying on xdotool
. It uses Zenity to present a menu with text fragments you saved, which you can select and paste. You could adapt this script to use a better menuing system like rofi
or dmenu
, or have the script first copy and delete a text fragment you typed, to replace it with the full text.