Linux terminal with custom buttons to execute scripts or commands

I’m aiming to improve my terminal usage for software development by creating a dashboard. First of all I want splits, vertical/horizontal, this is already possible with Tilix or Terminator (I don’t really like Tmux). But I’m missing a way to run scripts with my mouse. I run scripts often, like to clean or check the code. What I do is focus the terminals, press up arrow, and Enter, which is not as easy as clicking a button.

Is there a terminal that allows adding buttons at the top (or elsewhere), that allows me to run custom commands or scripts? For instance clicking "Check" might run "scripts/", which should run in a specific terminal and show its output.

Another button I’d use would be a button to restart a running program, like to update it after I changed the code.

Asked By: madprops


Not as far as I know.

You might, if you use some form of split-terminal, run dialog in one of the two sides, for example:

list=( */ )
folder=$( dialog --title "List directory" --cancel-label "Exit" 
                 --no-items --menu "Please choose one folder: " 
                 --output-fd 1 10 40 0 ${list[@]///} )
echo $folder

And depending a bit on your terminal, that may make it possible to use your mouse.

But, unless you run in console-mode, which hardly anyone does, it is far easier to just create a separate window. Look at tk and your favourite language (TCL/Tk, Perl/Tk, Python tkinter or even Bash/Tk) on how to do that.

If you want to embed a terminal window in your dashboard, you might use:

from tkinter import *
import os

root = Tk()
termf = Frame(root, height=400, width=500)
root.attributes("-fullscreen", True)    
termf.pack(fill=BOTH, expand=YES)
wid = termf.winfo_id()
os.system('xterm -into %d -geometry 400x500 -sb -e "ls; sleep 10" &' % wid)
Answered By: Ljm Dullaart

Take a look at Terminator‘s Custom Commands Menu plugin.

Enable it in Terminator’s Preferences, and then in the right-click menu… it should be pretty obvious.

If you’d like to have buttons instead of menu entries, it’s probably a relatively easy Python and GTK programming challenge to modify Terminator’s user interface accordingly.

Also I think you’ll want to modify Terminator’s source not to add a trailing n, i.e. not to execute the command immediately. It should be very easy to find the plugin’s source (inside Terminator’s official source) and within that the place where the newline is appended. (I think upstream would happily accept a patch that adds a corresponding UI toggle.)

Here’s why I think only a few terminal emulators have such a feature.

For instance clicking "Check" might run "scripts/", which should run in a specific terminal and show its output.

When you start up a terminal, it almost always(*) also runs a process: typically your shell.

You cannot "run" another program in the same terminal in the same fashion, next to your shell. The two would fight against each other for input, and maybe other resources as well. What you surely mean by "run" is to ask the already running shell to run your apps.

The way to do that is to pretend that you press the corresponding keys, i.e. synthesize input to the terminal (which then forwards them to the shell). [This particular step, in the Custom Commands plugin’s source, is done using the vte.feed_child() method.]

But there’s an inherent problem with this. You cannot know if the shell is at its prompt where it’s expecting input, whether the input line is currently empty, and no special mode (e.g. repeat count for a letter) is enabled. I.e. you cannot know if these input characters will be interpreted literally and form a command that you wish to execute.

You can have a partial command already entered, and then your desired button will add text to that. You can be in an app where each individual keystroke invokes a menu or something. You can be in vim’s command mode where injectcing a string like scripts/ will execute all sorts of random vim editing commands on the file. Etc.

In some contexts, pasting a predefined text does exactly what you want it to do. In other contexts it can easily cause a lot of harm. And the terminal can’t really tell which one is going to happen, therefore cannot protect you against such mistakes.

That’s why, instead of such UI features, people tend to prefer shell aliases and functions, or interactive shell command editing and related features (like history search).

(*) If you go down the rabbit hole of programming against VTE (the terminal emulation library that Terminator uses), you’ll find that it is possible not to run any command (not even the shell), just have that terminal sit there idle, and then you can add a button that starts up your preferred command directly in that terminal. Once it completes, you can fire up another command using one of the buttons. But again: there’s no shell then which you could type the next command into. In this case you don’t have to worry about the context. I’m really not sure however whether exploring this possibility is worth the efforts for you.

Answered By: egmont
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.