summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorguangzhi <xugzhi1987@gmail.com>2018-03-13 16:14:14 +0800
committerguangzhi <xugzhi1987@gmail.com>2018-03-13 16:14:14 +0800
commit2b4984ecd0dccdf6fc1ddf1aa63725371e9234d2 (patch)
treeecd272c70002592a78649e2641a579a359897264
parent08774ba13f4c8d679dbabcd33f748b1002ee397b (diff)
downloadranger-2b4984ecd0dccdf6fc1ddf1aa63725371e9234d2.tar.gz
re-organize block regarding flag t issue #1108
Changes made to rifle.py:

* get `term` from `os.environ['TERMCMD']`, if failed, use `TERM`
* if `term` not found in executables, fall back to `xterm`
* choose `cmdflag` according to `term`, currently have 3 choices:
	* `-e`: tested terminals + versions:
		* xterm (331-1)
		* urxvt (9.22)
		* lxterminal (0.3.1-1)
		* konsole (17.12.2-1)
		* lilyterm (0.9.9.2-2)
		* cool-retro-term (1.0.1-1)
	* `-x`:
		* xfce4-terminal (0.8.7.1-1)
		* mate-terminal (1.20.0-1)
		* terminator (1.91-5)
		* gnome-terminal (3.26.2)
	* `--`:
		* gnome-terminal (3.26.2)

* terminals that are found not working when tested:
	* pantheon-terminal (0.4.3-2): not -e or -x or --execute
	  (people using elementary probably won't use ranger anyway).
	* terminology (1.1.1-1): not -e or -x
	* tilda (1.4.1-1): with -c tilda opens but not entering editor
	* kitty (0.8.0-1): don't think this has the functionality

* terminals haven't tested:
	* st
	* termite (having conflicts on my system)
	* iterm2
-rwxr-xr-xranger/ext/rifle.py48
1 files changed, 27 insertions, 21 deletions
diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py
index 8b1314c3..f11f6f2c 100755
--- a/ranger/ext/rifle.py
+++ b/ranger/ext/rifle.py
@@ -355,33 +355,39 @@ 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 = 'urxvt'
-                            cmdflag = '-e'
-                        elif term.startswith('rxvt-'):
-                            # Sometimes urxvt calls itself "rxvt-256color"
-                            if 'rxvt' in get_executables():
-                                term = 'rxvt'
-                            else:
-                                term = 'urxvt'
-                            cmdflag = '-e'
-                    else:
-                        term = os.environ['TERMCMD']
-                        if term in ['gnome-terminal', 'xfce4-terminal',
-                                    'mate-terminal', 'terminator']:
-                            cmdflag = '-x'
-                        elif term in ['lxterminal', ]:
-                            cmdflag = '-e'
-                        else:
-                            cmdflag = '-e'
+                    term = os.environ.get('TERMCMD', os.environ['TERM'])
 
                     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.lower() 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']:
+                        cmdflag = '-e'
+                    elif term.lower() 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',
+                                          #'iterm2']:
+                        #pass
+                    else:
                         cmdflag = '-e'
 
                     os.environ['TERMCMD'] = term