summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--doc/ranger.13
-rw-r--r--doc/ranger.pod4
-rw-r--r--ranger/core/actions.py8
-rw-r--r--ranger/core/helper.py2
-rw-r--r--ranger/core/main.py6
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<targetfile>, 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<targetfile>.
 
+=item B<--selectfile>=I<targetfile>
+
+Open ranger with I<targetfile> selected.
+
 =item B<--copy-config>=I<file>
 
 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()