From 9dd669c7339442a38e87d0954efd7da6aaf258a1 Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 9 Aug 2012 03:05:52 +0200 Subject: 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. --- ranger/config/rifle.conf | 2 -- 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) -- cgit 1.4.1-2-gfad0 id='n4' href='#n4'>4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31