5

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!

5

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.

  • Thanks! I wasn't aware of the x-terminal-emulator feature - that solve my issue. – garzai Jun 22 '16 at 16:02
  • that doesn't work for me. I'm on Manjaro and ranger doesn't launch gnome-terminal for me. – Jason Sep 8 '17 at 8:03
  • No, rifle.py is used for opening a terminal, and get_term() just gives the terminal name which is not the problem – Jason Mar 11 '18 at 0:01
0

I'm now pretty sure that runner.py is irrelevant. rifle.py is the file to change.

At around line 375, there is a line:

cmd = [os.environ['TERMCMD'], '-e'] + cmd

Should try to change the '-e' flag to something else, depending on what your $TERMCMD is. I've tested a few different terminals and these are working for me:

  • gnome-terminal: change to '--' or '-x'
  • xfce4-terminal: '-x'
  • lxterminal: '-e'
  • mate-terminal: '-x'
  • terminator: '-x'

I haven't checked others, but it will probably be one of '--', '-e', '-x'.

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.