1

How do I open the default terminal emulator in a bash script? For example I want my wine game to launch inside whatever terminal emulator is set as default, hence providing me with a debug interface.

My script goes as follows:

cd "/path/to/wine game's dir/
WINEPREFIX="/path/to/wine prefix" wine "/path/to/wine game's dir/exe" 

I put all that in a .sh and to execute it i run bash /path/to/script

But like I said I'd like for it to launch a terminal window so i can see the output...

oxr463
  • 1,240
hm11
  • 53
  • I'm not quite sure why you need the terminal. Does Wine require a graphical terminal (I've never used Wine)? If it's so you can see the output, then what about looking in the terminal where you launch the script? – Kusalananda Jun 11 '19 at 18:01
  • 1
    You can view the game's debugging via the terminal and spot issues, i use straight up wine so i can make launchers for my games. – hm11 Jun 11 '19 at 20:13

2 Answers2

2

There is no default terminal emulator. If you attempt to invoke XTerm, and it is not installed, there is no default terminal emulator that gets run instead. This is even more of a misnomer than "default shell" (for login shell set in the account database, preferred shell set in an environment variable, or supplier of sh).

There is the individual user's preferred terminal emulator, and (on some operating systems) a system-wide preferred terminal emulator.

system-wide

The latter is set on Debian and derivative operating systems via its alternatives system, as x-terminal-emulator. This command will invoke, and its manual page will be the manual page of, one of a number of (installed) GUI terminal emulator programs, amongst which the system administrator can switch with the command:

update-alternatives --config x-terminal-emulator

On operating systems that have the i3 window manager available there is a similar, but not quite the same i3-sensible-terminal command, which attempts to look at the value of the (idiosyncratic) TERMINAL environment variable, run x-terminal-emulator, or one of a long hardwired list. Compare (and contrast) this with Debian's sensible-pager and sensible-editor commands.

per-user

The configuration of per-user preferred terminal emulators is a bit more complex. It varies by desktop, and some of the system-wide preference mechanisms have per-user overrides.

  • For the i3 window manager, i3-sensible-terminal actually is the desktop's way of starting the preferred terminal emulator, and its per-user configuration is an environment variable.
  • For GNOME, there are settings in the GNOME settings database, read with:
    gsettings get org.gnome.desktop.default-applications.terminal exec
    gsettings get org.gnome.desktop.default-applications.terminal exec-arg
  • For KDE, it is a setting named TerminalApplication in the kdeglobals configuration file, read with:
    kreadconfig --file kdeglobals --group General --key TerminalApplication --default konsole

GUI pagers

Of course, on the gripping hand you don't need a terminal emulator. You could just as well use a pager program that has a GUI and a follow mode:

WINEPREFIX="/path/to/wine prefix" wine "/path/to/wine game's dir/exe" 2>&1 |
some-gui-text-viewer --follow -

Unfortunately, this is a bit of a gap in free software toolsets.

There are very few plain and simple GUI text file viewers. The commonest suggestion that people make is to use a text file editor as a text file viewer, with tools like Kate, KWrite, or GVIM being given appropriate options or arguments telling them to treat their standard inputs as a text file to be edited. dtpad had a -viewOnly option, similarly.

Dedicated text viewers that are not text editors do exist. One might (I have not tried this.) also be able to bodge Mark Thomas Eriksen's seetxt into working as a filter by giving it /dev/stdin as the filename. (And again, you might not. It is a known difficulty for text file viewers to be unhappy when their input files are not seekable, as a pipe is not. This tool might be one such.) There are also tools such as Roland Baudin's xfv and KDE's kless.

But apparently none of these have an equivalent the abilities of TUI tools, such as less, to keep reading as more input arrives whilst allowing the user to view the existing text.

Further reading

JdeBP
  • 68,745
0
  • XFCE through exo-utils:

    exo-open --launch TerminalEmulator "bash -c '/path/to/script'"

...or configure your script header with a sha-bang ( like #!/bin/bash ) e make it executable

chmod +x '/path/to/script' and you don’t need the bash -c:

exo-open --launch TerminalEmulator '/path/to/script'
  • But with x-terminal-emulator you can use your default terminal options

(type man x-terminal-emulator):

x-terminal-emulator -e "bash -c '/path/to/script'"

… or if it is executable with a sha-bang:

x-terminal-emulator -e '/path/to/script'
  • Xterm itself (present in most linux distributions). You can even use its options to make it look different:

    xterm -bg white -fg black -fa Monospace -fs 11 -iconic -geometry 60x10 -e bash -c '/path/to/script'

or

xterm -bg white -fg black -fa Monospace -fs 11 -iconic -geometry 60x10 -e /path/to/script

-bg = background color

-fg = foreground (fonts) color

-fa = font name

-fs = font size

-iconic = minimized

-geometry = window size

-e program [ arguments ... ] specifies the program and its command line arguments to be run in the xterm window