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 ++++ ranger/core/actions.py | 8 ++++++-- ranger/core/helper.py | 2 ++ ranger/core/main.py | 6 ++++++ 5 files changed, 21 insertions(+), 2 deletions(-) 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 diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 5364f391..3300a534 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -344,8 +344,12 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): def select_file(self, path): path = path.strip() - if self.enter_dir(os.path.dirname(path)): - self.env.cwd.move_to_obj(path) + dirname = os.path.dirname(path) + if dirname: + if self.enter_dir(dirname): + self.env.cwd.move_to_obj(path) + else: + self.env.cwd.move_to_obj(join(self.env.cwd.path, path)) def history_go(self, relative): """Move back and forth in the history""" diff --git a/ranger/core/helper.py b/ranger/core/helper.py index c22a52b8..88072e13 100644 --- a/ranger/core/helper.py +++ b/ranger/core/helper.py @@ -66,6 +66,8 @@ def parse_arguments(): ", it will write the name of the last visited directory to TARGET") parser.add_option('--list-unused-keys', action='store_true', help="List common keys which are not bound to any action.") + parser.add_option('--selectfile', type='string', metavar='filepath', + help="Open ranger with supplied file selected.") options, positional = parser.parse_args() arg = OpenStruct(options.__dict__, targets=positional) diff --git a/ranger/core/main.py b/ranger/core/main.py index c87a4660..49513125 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -49,6 +49,9 @@ def main(): SettingsAware._setup(clean=arg.clean) + if arg.selectfile: + arg.targets.insert(0, os.path.dirname(arg.selectfile)) + targets = arg.targets or ['.'] target = targets[0] if arg.targets: @@ -97,6 +100,9 @@ def main(): from ranger.ext import curses_interrupt_handler curses_interrupt_handler.install_interrupt_handler() + if arg.selectfile: + fm.select_file(arg.selectfile) + # Run the file manager fm.initialize() fm.ui.initialize() -- cgit 1.4.1-2-gfad0 From 9ab9f65217df8dd75e171702bee2943ca295e956 Mon Sep 17 00:00:00 2001 From: David Pugnasse Date: Tue, 25 Oct 2011 02:15:53 +0200 Subject: core.main: fix --selectfile with relative paths --- ranger/core/actions.py | 8 ++------ ranger/core/main.py | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 3300a534..5364f391 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -344,12 +344,8 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): def select_file(self, path): path = path.strip() - dirname = os.path.dirname(path) - if dirname: - if self.enter_dir(dirname): - self.env.cwd.move_to_obj(path) - else: - self.env.cwd.move_to_obj(join(self.env.cwd.path, path)) + if self.enter_dir(os.path.dirname(path)): + self.env.cwd.move_to_obj(path) def history_go(self, relative): """Move back and forth in the history""" diff --git a/ranger/core/main.py b/ranger/core/main.py index 49513125..14e4b1f6 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -50,6 +50,7 @@ def main(): SettingsAware._setup(clean=arg.clean) if arg.selectfile: + arg.selectfile = os.path.abspath(arg.selectfile) arg.targets.insert(0, os.path.dirname(arg.selectfile)) targets = arg.targets or ['.'] -- cgit 1.4.1-2-gfad0