From 8a2d5352480629aeb7a983ea4ddadf7005223907 Mon Sep 17 00:00:00 2001 From: David Pugnasse Date: Mon, 24 Oct 2011 00:58:33 +0200 Subject: core.main: added --selectfile option --- doc/ranger.1 | 3 +++ doc/ranger.pod | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'doc') diff --git a/doc/ranger.1 b/doc/ranger.1 index e9f00501..c1a5b381 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -178,6 +178,9 @@ selected files into \fItargetfile\fR, adding one newline after each filename. .IX Item "--choosedir=targetfile" Allows you to pick a directory with ranger. When you exit ranger, it will write the last visited directory into \fItargetfile\fR. +.IP "\fB\-\-selectfile\fR=\fItargetfile\fR" 14 +.IX Item "--selectfile=targetfile" +Open ranger with \fItargetfile\fR selected. .IP "\fB\-\-copy\-config\fR=\fIfile\fR" 14 .IX Item "--copy-config=file" Create copies of the default configuration files in your local configuration diff --git a/doc/ranger.pod b/doc/ranger.pod index 069b9de1..8943b476 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -67,6 +67,10 @@ selected files into I, adding one newline after each filename. Allows you to pick a directory with ranger. When you exit ranger, it will write the last visited directory into I. +=item B<--selectfile>=I + +Open ranger with I selected. + =item B<--copy-config>=I Create copies of the default configuration files in your local configuration -- cgit 1.4.1-2-gfad0 From d6e61b1d3004ce58fc58a9d6035498b13e6f2089 Mon Sep 17 00:00:00 2001 From: M Rawash Date: Sun, 11 Dec 2011 21:58:02 +0200 Subject: Added documentation for new flags --- doc/ranger.1 | 7 ++++++- doc/ranger.pod | 5 +++++ ranger/defaults/apps.py | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'doc') 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 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/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" -- cgit 1.4.1-2-gfad0 From c2b71f721ba4fec22e6b8135508e07cb56df3320 Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 18 Jan 2012 16:21:20 +0100 Subject: Added doc for TERMCMD and integrated it in commands.py --- doc/ranger.pod | 7 +++++++ ranger/core/runner.py | 4 +++- ranger/defaults/commands.py | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/ranger.pod b/doc/ranger.pod index e261ca60..65615a8e 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -956,6 +956,13 @@ program out of "vim", "emacs" and "nano". Defines the shell that ranger is going to use with the :shell command and the "S" key. Defaults to "bash". +=item TERMCMD + +Defines the terminal emulator command that ranger is going to use with the +:terminal command and the "t" run flag. Defaults to "x-terminal-emulator" or +"xterm" + + =item XDG_CONFIG_HOME Specifies the directory for configuration files. Defaults to F<$HOME/.config>. diff --git a/ranger/core/runner.py b/ranger/core/runner.py index ba6d82a8..17cdcca5 100644 --- a/ranger/core/runner.py +++ b/ranger/core/runner.py @@ -204,7 +204,9 @@ class Runner(object): 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'] + term = os.environ.get('TERMCMD', os.environ.get('TERM')) + if term not in get_executables(): + term = 'x-terminal-emulator' if term not in get_executables(): term = 'xterm' if isinstance(action, str): diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py index da0c6735..ba9030c5 100644 --- a/ranger/defaults/commands.py +++ b/ranger/defaults/commands.py @@ -459,6 +459,11 @@ class terminal(Command): Spawns an "x-terminal-emulator" starting in the current directory. """ def execute(self): + command = os.environ.get('TERMCMD', os.environ.get('TERM')) + if command not in get_executables(): + command = 'x-terminal-emulator' + if command not in get_executables(): + command = 'xterm' self.fm.run('x-terminal-emulator', flags='d') -- cgit 1.4.1-2-gfad0 From 47c2cf6920324da597cf969329c0abb59591c9ca Mon Sep 17 00:00:00 2001 From: M Rawash Date: Fri, 27 Jan 2012 00:14:55 +0200 Subject: new :relink command --- doc/ranger.1 | 8 ++++++++ doc/ranger.pod | 4 ++++ ranger/defaults/commands.py | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) (limited to 'doc') diff --git a/doc/ranger.1 b/doc/ranger.1 index 94d5387d..06b08d50 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -741,6 +741,9 @@ it by typing `` or '' the next time you start ranger. .IX Item "rename newname" Rename the current file. If a file with that name already exists, the renaming will fail. Also try the key binding A for appending something to a file name. +.IP "relink \fInewpath\fR" 2 +.IX Item "relink newpath" +Change the link destination of the current symlink file to . First will load the original link. .IP "save_copy_buffer" 2 .IX Item "save_copy_buffer" Save the copy buffer from \fI~/.config/ranger/copy_buffer\fR. This can be used to @@ -869,6 +872,11 @@ program out of \*(L"vim\*(R", \*(L"emacs\*(R" and \*(L"nano\*(R". .IX Item "SHELL" Defines the shell that ranger is going to use with the :shell command and the \*(L"S\*(R" key. Defaults to \*(L"bash\*(R". +.IP "\s-1TERMCMD\s0" 8 +.IX Item "TERMCMD" +Defines the terminal emulator command that ranger is going to use with the +:terminal command and the \*(L"t\*(R" run flag. Defaults to \*(L"x\-terminal-emulator\*(R" or +\&\*(L"xterm\*(R" .IP "\s-1XDG_CONFIG_HOME\s0" 8 .IX Item "XDG_CONFIG_HOME" Specifies the directory for configuration files. Defaults to \fI\f(CI$HOME\fI/.config\fR. diff --git a/doc/ranger.pod b/doc/ranger.pod index 65615a8e..93b69999 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -787,6 +787,10 @@ it by typing `` or '' the next time you start ranger. Rename the current file. If a file with that name already exists, the renaming will fail. Also try the key binding A for appending something to a file name. +=item relink I + +Change the link destination of the current symlink file to . First will load the original link. + =item save_copy_buffer Save the copy buffer from I<~/.config/ranger/copy_buffer>. This can be used to diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py index c9729999..d1f4cf16 100644 --- a/ranger/defaults/commands.py +++ b/ranger/defaults/commands.py @@ -818,6 +818,45 @@ class bulkrename(Command): cmdfile.close() +class relink(Command): + """ + :relink + + Changes the linked path of the currently highlighted symlink to + """ + + def execute(self): + from ranger.fsobject import File + + new_path = self.rest(1) + cf = self.fm.env.cf + + if not new_path: + return self.fm.notify('Syntax: relink ', bad=True) + + if not cf.is_link: + return self.fm.notify('%s is not a symlink!' % cf.basename, bad=True) + + if new_path == os.readlink(cf.path): + return + + try: + os.remove(cf.path) + os.symlink(new_path, cf.path) + except OSError as err: + self.fm.notify(err) + + self.fm.reset() + self.fm.env.cwd.pointed_obj = cf + self.fm.env.cf = cf + + def tab(self): + if not self.rest(1): + return self.line+os.readlink(self.fm.env.cf.path) + else: + return self._tab_directory_content() + + class help_(Command): """ :help -- cgit 1.4.1-2-gfad0 From e748d5056c907c5f9e46f6824442d47231a1ad32 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 12 Feb 2012 17:12:28 +0100 Subject: core.main: Allow multiple --cmd's, add man page entry for --cmd --- doc/ranger.1 | 6 +++++- doc/ranger.pod | 5 +++++ ranger/core/helper.py | 5 +++-- ranger/core/main.py | 3 ++- 4 files changed, 15 insertions(+), 4 deletions(-) (limited to 'doc') diff --git a/doc/ranger.1 b/doc/ranger.1 index 06b08d50..e58008e0 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.5.2" "10/24/2011" "ranger manual" +.TH RANGER 1 "ranger-1.5.2" "02/12/2012" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -204,6 +204,10 @@ the execution of this file type is explicitly handled in the configuration. When a filename is supplied, run it with the given \fIflags\fR to modify behavior. The execution of this file type is explicitly handled in the configuration. +.IP "\fB\-\-cmd\fR=\fIcommand\fR" 14 +.IX Item "--cmd=command" +Execute the command after the configuration has been read. Use this option +multiple times to run multiple commands. .IP "\fB\-\-version\fR" 14 .IX Item "--version" Print the version and exit. diff --git a/doc/ranger.pod b/doc/ranger.pod index 93b69999..0799f35d 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -99,6 +99,11 @@ When a filename is supplied, run it with the given I to modify behavior. The execution of this file type is explicitly handled in the configuration. +=item B<--cmd>=I + +Execute the command after the configuration has been read. Use this option +multiple times to run multiple commands. + =item B<--version> Print the version and exit. diff --git a/ranger/core/helper.py b/ranger/core/helper.py index 3f93e79c..c556b9bd 100644 --- a/ranger/core/helper.py +++ b/ranger/core/helper.py @@ -73,8 +73,9 @@ def parse_arguments(): help="List all files which are tagged with the given tag, default: *") parser.add_option('--profile', action='store_true', help="Print statistics of CPU usage on exit.") - parser.add_option('--cmd', type='string', metavar='COMMAND', - help="COMMAND will be executed after ranger has initialized") + parser.add_option('--cmd', action='append', type='string', metavar='COMMAND', + help="Execute COMMAND after the configuration has been read. " + "Use this option multiple times to run multiple commands.") options, positional = parser.parse_args() arg = OpenStruct(options.__dict__, targets=positional) diff --git a/ranger/core/main.py b/ranger/core/main.py index f80ee2d6..a17c6863 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -123,7 +123,8 @@ def main(): fm.ui.initialize() if arg.cmd: - fm.execute_console(arg.cmd) + for command in arg.cmd: + fm.execute_console(command) if ranger.arg.profile: import cProfile -- cgit 1.4.1-2-gfad0 From 824104ae627f276eee8ec88522c873a6b76c5ecc Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 12 Feb 2012 17:21:47 +0100 Subject: ranger.1: Added entry for --list-tagged-files --- doc/ranger.1 | 4 ++++ doc/ranger.pod | 5 +++++ 2 files changed, 9 insertions(+) (limited to 'doc') diff --git a/doc/ranger.1 b/doc/ranger.1 index e58008e0..60731bbc 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -191,6 +191,10 @@ directory. Existing ones will not be overwritten. Possible values: \fIall\fR, List common keys which are not bound to any action in the \*(L"browser\*(R" context. This list is not complete, you can bind any key that is supported by curses: use the key code returned by \f(CW\*(C`getch()\*(C'\fR. +.IP "\fB\-\-list\-tagged\-files\fR=\fItag\fR" 14 +.IX Item "--list-tagged-files=tag" +List all files which are tagged with the given tag. Note: Tags are single +characters. The default tag is \*(L"*\*(R" .IP "\fB\-\-fail\-unless\-cd\fR" 14 .IX Item "--fail-unless-cd" Return the exit code 1 if ranger is used to run a file instead of used for file diff --git a/doc/ranger.pod b/doc/ranger.pod index 0799f35d..926a8de0 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -83,6 +83,11 @@ List common keys which are not bound to any action in the "browser" context. This list is not complete, you can bind any key that is supported by curses: use the key code returned by C. +=item B<--list-tagged-files>=I + +List all files which are tagged with the given tag. Note: Tags are single +characters. The default tag is "*" + =item B<--fail-unless-cd> Return the exit code 1 if ranger is used to run a file instead of used for file -- cgit 1.4.1-2-gfad0 From 9ff49bf6b1004126b528b73c1d7822ce99581410 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 21 Feb 2012 14:48:00 +0100 Subject: ranger.1: fix vim script "RangerChooser" when no file is opened https://savannah.nongnu.org/bugs/?35556 --- doc/ranger.1 | 4 ++-- doc/ranger.pod | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'doc') diff --git a/doc/ranger.1 b/doc/ranger.1 index 60731bbc..fe2d2d1e 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.5.2" "02/12/2012" "ranger manual" +.TH RANGER 1 "ranger-1.5.2" "02/21/2012" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -906,7 +906,7 @@ opening in your current vim session. .PP .Vb 9 \& fun! RangerChooser() -\& silent !ranger \-\-choosefile=/tmp/chosenfile \`[ \-z \*(Aq%\*(Aq ] && echo \-n . || dirname %\` +\& exec "silent !ranger \-\-choosefile=/tmp/chosenfile " . expand("%:p:h") \& if filereadable(\*(Aq/tmp/chosenfile\*(Aq) \& exec \*(Aqedit \*(Aq . system(\*(Aqcat /tmp/chosenfile\*(Aq) \& call system(\*(Aqrm /tmp/chosenfile\*(Aq) diff --git a/doc/ranger.pod b/doc/ranger.pod index 926a8de0..f438cae7 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -1004,7 +1004,7 @@ This is a vim function which allows you to use ranger to select a file for opening in your current vim session. fun! RangerChooser() - silent !ranger --choosefile=/tmp/chosenfile `[ -z '%' ] && echo -n . || dirname %` + exec "silent !ranger --choosefile=/tmp/chosenfile " . expand("%:p:h") if filereadable('/tmp/chosenfile') exec 'edit ' . system('cat /tmp/chosenfile') call system('rm /tmp/chosenfile') -- cgit 1.4.1-2-gfad0 From f16bbc20854a051ddedf6ab43cffd89ddbcef27f Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 5 Mar 2012 11:11:30 +0100 Subject: Removed unnecessary spaces --- doc/ranger.1 | 4 ++-- doc/ranger.pod | 2 +- ranger/defaults/commands.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'doc') diff --git a/doc/ranger.1 b/doc/ranger.1 index fe2d2d1e..823b31c7 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.5.2" "02/21/2012" "ranger manual" +.TH RANGER 1 "ranger-1.5.2" "03/05/2012" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -296,7 +296,7 @@ used in the commands :open_with (key \*(L"r\*(R") and :shell (key \*(L"!\*(R"). \& 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) +\& r Run application with root privilege (requires sudo) \& t Run application in a new terminal window .Ve .PP diff --git a/doc/ranger.pod b/doc/ranger.pod index f438cae7..e8c45826 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -200,7 +200,7 @@ 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) + 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 diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py index d1f4cf16..a89dd0f7 100644 --- a/ranger/defaults/commands.py +++ b/ranger/defaults/commands.py @@ -836,10 +836,10 @@ class relink(Command): if not cf.is_link: return self.fm.notify('%s is not a symlink!' % cf.basename, bad=True) - + if new_path == os.readlink(cf.path): return - + try: os.remove(cf.path) os.symlink(new_path, cf.path) -- cgit 1.4.1-2-gfad0 From 23b7f16961a7b679dec16f6ee91401a6b8f6ca82 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 5 Mar 2012 11:27:16 +0100 Subject: Added $RANGER_LEVEL environment variable (see man page) --- doc/ranger.1 | 13 +++++++++++++ doc/ranger.pod | 13 +++++++++++++ ranger/core/main.py | 7 +++++++ 3 files changed, 33 insertions(+) (limited to 'doc') diff --git a/doc/ranger.1 b/doc/ranger.1 index 823b31c7..433bb8a7 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -872,6 +872,11 @@ with T. To assign a named tag, type ". .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" These environment variables have an effect on ranger: +.IP "\s-1RANGER_LEVEL\s0" 8 +.IX Item "RANGER_LEVEL" +Ranger sets this environment variable to \*(L"1\*(R" or increments it if it already +exists. External programs can determine whether they were spawned from ranger +by checking for this variable. .IP "\s-1EDITOR\s0" 8 .IX Item "EDITOR" Defines the editor to be used for the \*(L"E\*(R" key. Defaults to the first installed @@ -899,6 +904,14 @@ Using PYTHONOPTIMIZE=2 (like python \-OO) will additionally discard any docstrings. Using this will disable the key on commands. .SH "EXAMPLES" .IX Header "EXAMPLES" +.SS "\s-1BASH:\s0 Display that the shell spawned from ranger:" +.IX Subsection "BASH: Display that the shell spawned from ranger:" +By putting this in ~/.bashrc, \*(L"(in ranger) \*(R" will be displayed next to your +prompt to notify you that the shell spawned from ranger. +.PP +.Vb 1 +\& [ \-n "$RANGER_LEVEL" ] && PS1="$PS1"\*(Aq(in ranger) \*(Aq +.Ve .SS "\s-1VIM:\s0 File Chooser" .IX Subsection "VIM: File Chooser" This is a vim function which allows you to use ranger to select a file for diff --git a/doc/ranger.pod b/doc/ranger.pod index e8c45826..9f8b4f04 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -960,6 +960,12 @@ These environment variables have an effect on ranger: =over 8 +=item RANGER_LEVEL + +Ranger sets this environment variable to "1" or increments it if it already +exists. External programs can determine whether they were spawned from ranger +by checking for this variable. + =item EDITOR Defines the editor to be used for the "E" key. Defaults to the first installed @@ -998,6 +1004,13 @@ docstrings. Using this will disable the key on commands. =head1 EXAMPLES +=head2 BASH: Display that the shell spawned from ranger: + +By putting this in ~/.bashrc, "(in ranger) " will be displayed next to your +prompt to notify you that the shell spawned from ranger. + + [ -n "$RANGER_LEVEL" ] && PS1="$PS1"'(in ranger) ' + =head2 VIM: File Chooser This is a vim function which allows you to use ranger to select a file for diff --git a/ranger/core/main.py b/ranger/core/main.py index 4bb4c48a..b4629801 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -38,6 +38,13 @@ def main(): except: print("Warning: Unable to set locale. Expect encoding problems.") + # so that programs can know that ranger spawned them: + level = 'RANGER_LEVEL' + if level in os.environ and os.environ[level].isdigit(): + os.environ[level] = str(int(os.environ[level]) + 1) + else: + os.environ[level] = '1' + if not 'SHELL' in os.environ: os.environ['SHELL'] = 'bash' -- cgit 1.4.1-2-gfad0