diff options
author | hut <hut@lavabit.com> | 2011-12-17 21:57:50 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-12-17 21:57:50 +0100 |
commit | 7d820eebd049b8bf67a37ddd4046099e1569882c (patch) | |
tree | 401b006a79ccf0c82ca28ee3846bf8b3b9a53f66 | |
parent | 703b35122c4db45b601547a5f341fd7dbc6f0052 (diff) | |
parent | d6e61b1d3004ce58fc58a9d6035498b13e6f2089 (diff) | |
download | ranger-7d820eebd049b8bf67a37ddd4046099e1569882c.tar.gz |
Merge https://github.com/gwash/ranger
-rw-r--r-- | doc/ranger.1 | 7 | ||||
-rw-r--r-- | doc/ranger.pod | 5 | ||||
-rw-r--r-- | ranger/core/runner.py | 28 | ||||
-rw-r--r-- | ranger/defaults/apps.py | 2 |
4 files changed, 39 insertions, 3 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1 index c1a5b381..94d5387d 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -282,18 +282,23 @@ Note: The bookmarks ' (Apostrophe) and ` (Backtick) are the same. Flags give you a way to modify the behavior of the spawned process. They are used in the commands :open_with (key \*(L"r\*(R") and :shell (key \*(L"!\*(R"). .PP -.Vb 5 +.Vb 7 \& s Silent mode. Output will be discarded. \& d Detach the process. (Run in background) \& p Redirect output to the pager \& w Wait for an Enter\-press when the process is done \& c Run the current file only, instead of the selection +\& r Run application with root privilege (requires sudo) +\& t Run application in a new terminal window .Ve .PP By default, all the flags are off unless specified otherwise in the \fIapps.py\fR configuration file. You can specify as many flags as you want. An uppercase flag negates the effect: \*(L"ddcccDs\*(R" is equivalent to \*(L"cs\*(R". .PP +The \*(L"t\*(R" flag looks for the environment variable \s-1TERMCMD\s0, and uses it as the +terminal command, if it's not set it'll use xterm. +.PP Examples: \f(CW\*(C`:open_with p\*(C'\fR will pipe the output of that process into the pager. \f(CW\*(C`:shell \-w df\*(C'\fR will run \*(L"df\*(R" and wait for you to press Enter before switching back to ranger. diff --git a/doc/ranger.pod b/doc/ranger.pod index 8943b476..e261ca60 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -190,11 +190,16 @@ used in the commands :open_with (key "r") and :shell (key "!"). p Redirect output to the pager w Wait for an Enter-press when the process is done c Run the current file only, instead of the selection + r Run application with root privilege (requires sudo) + t Run application in a new terminal window By default, all the flags are off unless specified otherwise in the F<apps.py> configuration file. You can specify as many flags as you want. An uppercase flag negates the effect: "ddcccDs" is equivalent to "cs". +The "t" flag looks for the environment variable TERMCMD, and uses it as the +terminal command, if it's not set it'll use xterm. + Examples: C<:open_with p> will pipe the output of that process into the pager. C<:shell -w df> will run "df" and wait for you to press Enter before switching back to ranger. diff --git a/ranger/core/runner.py b/ranger/core/runner.py index 5d97489d..7d433652 100644 --- a/ranger/core/runner.py +++ b/ranger/core/runner.py @@ -30,15 +30,18 @@ d: detach the process. p: redirect output to the pager c: run only the current file (not handled here) w: wait for enter-press afterwards +r: run application with root privilege (requires sudo) +t: run application in a new terminal window (An uppercase key negates the respective lower case flag) """ import os import sys from subprocess import Popen, PIPE +from ranger.ext.get_executables import get_executables -ALLOWED_FLAGS = 'sdpwcSDPWC' +ALLOWED_FLAGS = 'sdpwcartSDPWCART' def press_enter(): @@ -160,7 +163,6 @@ class Runner(object): wait_for_enter = False devnull = None - popen_kws['args'] = action if 'shell' not in popen_kws: popen_kws['shell'] = isinstance(action, str) if 'stdout' not in popen_kws: @@ -189,7 +191,29 @@ class Runner(object): if 'w' in context.flags: if not pipe_output and context.wait: # <-- sanity check wait_for_enter = True + if 'r' in context.flags: + if 'sudo' not in get_executables(): + return self._log("Can not run with 'r' flag, sudo is not installed!") + if isinstance(action, str): + action = 'sudo '+action + else: + action = ['sudo']+action + toggle_ui = True + context.wait = True + if 't' in context.flags: + if 'DISPLAY' not in os.environ: + return self._log("Can not run with 't' flag, no display found!") + term = os.environ['TERMCMD'] if 'TERMCMD' in os.environ else os.environ['TERM'] + if term not in get_executables(): + term = 'xterm' + if isinstance(action, str): + action = term+' -e '+action + else: + action = [term,'-e']+action + toggle_ui = False + context.wait = False + popen_kws['args'] = action # Finally, run it if toggle_ui: diff --git a/ranger/defaults/apps.py b/ranger/defaults/apps.py index 0a68d006..77c66c7b 100644 --- a/ranger/defaults/apps.py +++ b/ranger/defaults/apps.py @@ -35,6 +35,8 @@ # p Redirect output to the pager # w Wait for an Enter-press when the process is done # c Run the current file only, instead of the selection +# r Run application with root privilege +# t Run application in a new terminal window # # To implement flags in this file, you could do this: # context.flags += "d" |