Linux – Ranger file manager – Open gnome-terminal instead of xterm

environment-variablesfile-managergnome-terminallinuxxterm

I recently started using Ranger as my default file manager, and I'm really enjoying it. Right now, I've managed to change rifle.conf so that when I play audio or video from Ranger, mpv opens in a new xterm window and the media starts to play.

However, if possible, I would like Ranger to open the gnome-terminal instead of xterm. In /.config/ranger/rifle.conf, it says that using the t flag will run the program in a new terminal:

If $TERMCMD is not defined, rifle will attempt to extract it from $TERM

I tried setting $TERMCMD in both my .profile and .bashrc files, but even though echo $TERMCMD would print "gnome-terminal", Ranger would still open xterm. I also messed with setting $TERM to "gnome-terminal", but that was messy and I decided to leave it alone.

Any suggestions? Thanks!

Best Answer

As of 2017, the source-code (runner.py) did this:

        term = os.environ.get('TERMCMD', os.environ.get('TERM'))
        if term not in get_executables():
            term = 'x-terminal-emulator'
        if term not in get_executables():
            term = 'xterm'
        if isinstance(action, str):
            action = term + ' -e ' + action
        else:
            action = [term, '-e'] + action

so you should be able to put any xterm-compatible program name in TERMCMD. However, note the use of -e (gnome-terminal doesn't match xterm's behavior). If you are using Debian/Ubuntu/etc, the Debian packagers have attempted to provide a wrapper to hide this difference in the x-terminal-emulator feature. If that applies to you, you could set TERMCMD to x-terminal-emulator.

Followup - while the design of the TERMCMD feature has not changed appreciably since mid-2016, the location within the source has changed:

That is implemented in get_term:

def get_term():
    """Get the user terminal executable name.
    Either $TERMCMD, $TERM, "x-terminal-emulator" or "xterm", in this order.
    """
    command = environ.get('TERMCMD', environ.get('TERM'))
    if shlex.split(command)[0] not in get_executables():
        command = 'x-terminal-emulator'
        if command not in get_executables():
            command = 'xterm'
    return command

which uses x-terminal-emulator as before.

There is a related use of TERMCMD in rifle.py, used for executing commands rather than (as asked in the question) for opening a terminal. Either way, the key to using ranger is x-terminal-emulator, since GNOME Terminal's developers do not document their command-line interface, while Debian developers have provided this workaround.

Quoting from Bug 701691 – -e accepts only one term; all other terminal emulators accept more than one term (which the developer refused to fix, marking it "not a bug"):

Christian Persch 2013-06-06 16:02:54 UTC

There are no docs for the gnome-terminal command line options.

Related Question