This is a card in Dave's Virtual Box of Cards.

xfce4-terminal Automation

Page created: 2024-11-30

See also the larger blog post that spawned this: OpenBSD Blog #10: ksh profiles and startup automation

The xfce4-terminal executable has a bunch of neat options that can assist in scripting the setup of a terminal setup for a specific purpose or project.

The one I’m using right now is the command line option to open up a tab. I also have each tab run a command to do a different bit of setup to get my development environment ready for my current project.

The general form is:

xfce4-terminal --tab -T <title> -x <rest of line is command to run>

Which, if run within an existing xfce4-terminal window, will open a new tab, label it with the title, and then run the given command in that tab.

Here’s the lines from my actual shell script:

xfce4-terminal --tab -T 'Vim(Dev)' -x ssh -t deimos 'export DEV=ft1 ; ksh -l'
xfce4-terminal --tab -T 'Error Log' -x ssh -t deimos 'export DEV=ft2 ; ksh -l'
xfce4-terminal --tab -T 'SQLite' -x ssh -t deimos 'export DEV=ft3 ; ksh -l'
xfce4-terminal --tab -T 'Ratf' -x ssh -t phobos

All four open SSH sessions. The first three set an environment variable DEV, which is checked in .profile.

For the specifics of the SSH startup process and why I’m using an environment variable versus some other solution, see ssh-startup-commands.

Another real example

Here’s a very similar setup ripped straight out of my connection script for another development environment.

The exact details of my setup aren’t important. But this example demonstrates:

  • Exporting two environment variables on the remote computer (DSPRE and DEVENV).

  • One of the environment variables has a value ($2) from the local environment, so double-quotes are needed to allow interpolation of the variable.

  • Using bash instead of ksh (Bash also supports the -l startup option.)

echo "Connecting to devsite prefix '$2' for three 'side' tabs..."
h=devbox

# terminal -T to set tab title
# terminal -x to execute command
# ssh -t to force pseudo-terminal
# bash -l makes bash run as a login shell
xfce4-terminal --tab -T 'Bash'  -x ssh -t $h "export DSPRE=$2 DEVENV=Bash  ; bash -l"
xfce4-terminal --tab -T 'SQL'   -x ssh -t $h "export DSPRE=$2 DEVENV=SQL   ; bash -l"
xfce4-terminal --tab -T 'Error' -x ssh -t $h "export DSPRE=$2 DEVENV=Error ; bash -l"