I've got the following hardcoded list of terminals in my application:

"/usr/bin/konsole", // KDE
"/usr/bin/gnome-terminal", // Gnome
"/usr/bin/pantheon-terminal" // Pantheon (Elementary OS)

I then simply grab the first entry from this list that points to an existing file. Obviously, the problem is that the program stops working as soon as it's run on a system with unknown terminal binary. So, can I determine it in some generic way? Via some standard environment variable, perhaps?

  • IMHO it might be useful to explain what is it that your program intents to do with such terminal binary info: launch it? determine if it is the one actually running? etc. – Dan Cornilescu Jul 9 '15 at 19:24
  • @DanCornilescu: just launch it in the specified working directory. – Violet Giraffe Jul 9 '15 at 20:03

First I'd only keep the terminal executable names in the list and dynamically determine their actual paths based on the PATH env var - depending on the distribution and/or the installation options they might be in other locations. Or use which <terminal executable> which does that for you.

I'd use xterm as the final fallback terminal - it's pretty much standard on any X-Windows installation.

Other convenience considerations:

  • check if DISPLAY is set - if it's not most likely the terminals won't run
  • try to determine the actual graphics environment and first try the more appropriate one for it. WINDOWMANAGER may help. Specific window managers typically set their own env vars, for example in my case KDE sets: KDE_SESSION_UID, KDE_FULL_SESSION, KDE_MULTIHEAD, KDE_SESSION_VERSION.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.