diff options
author | hut <hut@lavabit.com> | 2012-08-09 03:05:52 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2012-08-09 03:05:52 +0200 |
commit | 9dd669c7339442a38e87d0954efd7da6aaf258a1 (patch) | |
tree | 938dfc2a3d3dab3e837bb9424ed29187c007bdb5 | |
parent | 25b87f8a8a24ddd571e792b6dedff5e6f69c3069 (diff) | |
download | ranger-9dd669c7339442a38e87d0954efd7da6aaf258a1.tar.gz |
ext.rifle: flags now work with commands with pipes, semicolons etc
rough explanation: before, the "t" flag would run the program in a terminal by prepending something like "xterm -e " to the command. If the command is "ls | less", it would result in "xterm -e ls | less". This commit changes it so the result looks more like "xterm -e sh -c 'ls | less'" and works as intended.
-rw-r--r-- | ranger/config/rifle.conf | 2 | ||||
-rwxr-xr-x | ranger/ext/rifle.py | 26 |
2 files changed, 21 insertions, 7 deletions
diff --git a/ranger/config/rifle.conf b/ranger/config/rifle.conf index bb876310..0690dbd3 100644 --- a/ranger/config/rifle.conf +++ b/ranger/config/rifle.conf @@ -42,8 +42,6 @@ # t | Run the program in a new terminal. If $TERMCMD is not defined, # | rifle will attempt to extract it from $TERM. # | New command = $TERMCMD -e $command -# -# NOTE: FLAGS DO NOT WORK PROPERLY WHEN PIPES ARE IN THE COMMAND #------------------------------------------- # Websites diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index e092f620..12da48f1 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -223,7 +223,7 @@ class Rifle(object): command = "set -- '%s'" % _filenames + '\n' # Apply flags - command += self._apply_flags(action, flags) + command += action return command def _apply_flags(self, action, flags): @@ -323,11 +323,27 @@ class Rifle(object): self.hook_before_executing(command, self._mimetype, self._app_flags) try: if 'r' in flags: - p = Popen(['sudo', '-E', 'su', '-mc', command], - env=self.hook_environment(os.environ), shell=False) + prefix = ['sudo', '-E', 'su', '-mc'] else: - p = Popen(command, env=self.hook_environment(os.environ), shell=True) - p.wait() + prefix = ['/bin/sh', '-c'] + if 't' in flags: + if 'TERMCMD' not in os.environ: + term = os.environ['TERM'] + if term.startswith('rxvt-unicode'): + term = 'urxvt' + if term not in get_executables(): + self.hook_logger("Can not determine terminal command. " + "Please set $TERMCMD manually.") + os.environ['TERMCMD'] = term + cmd = [os.environ['TERMCMD'], '-e'] + prefix + [command] + elif 'f' in flags: + exe = 'setsid' if 'setsid' in get_executables() else 'nohup' + cmd = [exe] + prefix + [command] + else: + cmd = prefix + [command] + p = Popen(cmd, env=self.hook_environment(os.environ)) + if not ('f' in flags or 't' in flags): + p.wait() finally: self.hook_after_executing(command, self._mimetype, self._app_flags) |