summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorguangzhi <xugzhi1987@gmail.com>2018-03-16 19:03:59 +0800
committerguangzhi <xugzhi1987@gmail.com>2018-03-16 19:03:59 +0800
commit7baa70ec2032e328439c286d0e671ef56be22e59 (patch)
tree2a7ec627d070cd8d9555f33b2b6e86b9f7e87a72
parentb84444110868a3b4be4dea89a76aa86b883f151f (diff)
downloadranger-7baa70ec2032e328439c286d0e671ef56be22e59.tar.gz
more terminals tested for fix of issue #1108
Handle aliases for 'xterm', 'xterm-256color' by using 'xterm' if
$TERMCMD starts with 'xterm'.

If $TERMCMD in ['urxvt', 'rxvt-unicode'], use 'urxvt'.

If $TERMCMD in ['rxvt', 'rxvt-256color'], use 'rxvt' if found, otherwise
'urxvt'.

Tested 'termite (13-1)', 'terminology (1.1.1-1)', 'pantheon-terminal (0.4.3-2)'
and 'st (1:0.7.r38.g0ac685f-1)', these all use the -e flag.

Tested 'tilda (1.4.1-1)', which uses -c flag.

'tilda', 'pantheon-terminal', 'terminology' and 'termite' don't work
with the '/bin/sh --set' scheme. As a temp fix, get the application
name and argument from `command` and compose the `cmd` list from these.
See line 397--407 for details.

Let's forget about mac users, shall we?
-rwxr-xr-xranger/ext/rifle.py56
1 files changed, 36 insertions, 20 deletions
diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py
index 0fd8046f..97dfb444 100755
--- a/ranger/ext/rifle.py
+++ b/ranger/ext/rifle.py
@@ -356,6 +356,20 @@ class Rifle(object):  # pylint: disable=too-many-instance-attributes
                 cmd = prefix + [command]
                 if 't' in flags:
                     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'
 
                     if term not in get_executables():
                         self.hook_logger("Can not determine terminal command.  "
@@ -364,33 +378,35 @@ class Rifle(object):  # pylint: disable=too-many-instance-attributes
                         term = 'xterm'
 
                     # Choose correct cmdflag accordingly
-                    if term.lower() in ['xfce4-terminal', 'mate-terminal',
-                                        'terminator']:
+                    if term in ['xfce4-terminal', 'mate-terminal', 'terminator']:
                         cmdflag = '-x'
-                    elif term.lower() in ['xterm', 'xterm-256color', 'urxvt',
-                                          'rxvt', 'rxvt-256color',
-                                          'rxvt-unicode', 'lxterminal',
-                                          'konsole', 'lilyterm',
-                                          'cool-retro-term']:
+                    elif term in ['xterm', 'urxvt', 'rxvt', 'lxterminal',
+                                  'konsole', 'lilyterm', 'cool-retro-term',
+                                  'terminology', 'pantheon-terminal', 'termite',
+                                  'st', 'stterm']:
                         cmdflag = '-e'
-                    elif term.lower() in ['gnome-terminal', ]:
+                    elif term in ['gnome-terminal', ]:
                         cmdflag = '--'
-                    # terminals that are found not working with -e or -x:
-                    # consider uncomment the next 2 lines
-                    # elif term.lower() in ['pantheon-terminal', 'terminology']:
-                    # term = 'xterm'
-                    # cmdflag = '-e'
-                    # 'tilda opens with -c but doesn't go into editor. Not sure.
-                    # elif term.lower() in ['tilda', ]:
-                    # cmdflag = '-c'
-                    # terminals not tested yet:
-                    # elif term.lower() in ['st', 'stterm', 'termite', 'kitty']:
-                    # pass
+                    elif term in ['tilda', ]:
+                        cmdflag = '-c'
                     else:
                         cmdflag = '-e'
 
                     os.environ['TERMCMD'] = term
-                    cmd = [os.environ['TERMCMD'], cmdflag] + cmd
+
+                    # 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))