summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xranger/ext/rifle.py68
1 files changed, 52 insertions, 16 deletions
diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py
index 672b0597..5c17839a 100755
--- a/ranger/ext/rifle.py
+++ b/ranger/ext/rifle.py
@@ -363,23 +363,59 @@ class Rifle(object):  # pylint: disable=too-many-instance-attributes
 
                 cmd = prefix + [command]
                 if 't' in flags:
-                    if 'TERMCMD' not in os.environ:
-                        term = os.environ['TERM']
-                        if term.startswith('rxvt-unicode'):
+                    term = os.environ.get('TERMCMD', os.environ['TERM'])
+                    # we can do this, can't we?
+                    term = term.lower()
+
+                    # handle aliases of xterm and urxvt, rxvt
+                    # match 'xterm', 'xterm-256color'
+                    if term.startswith('xterm'):
+                        term = 'xterm'
+                    if term in ['urxvt', 'rxvt-unicode']:
+                        term = 'urxvt'
+                    if term in ['rxvt', 'rxvt-256color']:
+                        if 'rxvt 'in get_executables():
+                            term = 'rxvt'
+                        else:
                             term = 'urxvt'
-                        elif term.startswith('rxvt-'):
-                            # Sometimes urxvt calls itself "rxvt-256color"
-                            if 'rxvt' in get_executables():
-                                term = 'rxvt'
-                            else:
-                                term = 'urxvt'
-                        if term not in get_executables():
-                            self.hook_logger("Can not determine terminal command.  "
-                                             "Please set $TERMCMD manually.")
-                            # A fallback terminal that is likely installed:
-                            term = 'xterm'
-                        os.environ['TERMCMD'] = term
-                    cmd = [os.environ['TERMCMD'], '-e'] + cmd
+
+                    if term not in get_executables():
+                        self.hook_logger("Can not determine terminal command.  "
+                                         "Please set $TERMCMD manually.")
+                        # A fallback terminal that is likely installed:
+                        term = 'xterm'
+
+                    # Choose correct cmdflag accordingly
+                    if term in ['xfce4-terminal', 'mate-terminal', 'terminator']:
+                        cmdflag = '-x'
+                    elif term in ['xterm', 'urxvt', 'rxvt', 'lxterminal',
+                                  'konsole', 'lilyterm', 'cool-retro-term',
+                                  'terminology', 'pantheon-terminal', 'termite',
+                                  'st', 'stterm']:
+                        cmdflag = '-e'
+                    elif term in ['gnome-terminal', ]:
+                        cmdflag = '--'
+                    elif term in ['tilda', ]:
+                        cmdflag = '-c'
+                    else:
+                        cmdflag = '-e'
+
+                    os.environ['TERMCMD'] = term
+
+                    # These terms don't work with the '/bin/sh set --' scheme
+                    # a temporary fix.
+                    if term in ['tilda', 'pantheon-terminal', 'terminology',
+                                'termite']:
+
+                        target = command.split(';')[0].split('--')[1].strip()
+                        app = command.split(';')[1].split('--')[0].strip()
+                        cmd = [os.environ['TERMCMD'], cmdflag, '%s %s'
+                               % (app, target)]
+                    else:
+                        cmd = [os.environ['TERMCMD'], cmdflag] + cmd
+
+                    # self.hook_logger('cmd: %s' %cmd)
+
                 if 'f' in flags or 't' in flags:
                     Popen_forked(cmd, env=self.hook_environment(os.environ))
                 else: