diff options
author | hut <hut@lavabit.com> | 2010-01-14 05:35:46 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-01-14 05:35:46 +0100 |
commit | 01c8834f9ff1e6990b5720d7efd3f350110df735 (patch) | |
tree | e6519b845d5d8efc2e64a5f1691c737b9f1030be | |
parent | 832b516c52e74b7180c0e5fc5d5c2d995d1aacf6 (diff) | |
download | ranger-01c8834f9ff1e6990b5720d7efd3f350110df735.tar.gz |
commands: added :edit command
-rw-r--r-- | ranger/actions.py | 11 | ||||
-rw-r--r-- | ranger/commands.py | 13 |
2 files changed, 21 insertions, 3 deletions
diff --git a/ranger/actions.py b/ranger/actions.py index a881f7c2..6aab4581 100644 --- a/ranger/actions.py +++ b/ranger/actions.py @@ -20,6 +20,7 @@ from ranger.shared import EnvironmentAware, SettingsAware from ranger import fsobject from ranger.gui.widgets import console_mode as cmode from ranger.applications import run +from ranger.fsobject import File class Actions(EnvironmentAware, SettingsAware): search_method = 'ctime' @@ -242,11 +243,15 @@ class Actions(EnvironmentAware, SettingsAware): def execute_command(self, cmd, **kw): return run(fm=self, action=cmd, **kw) - def edit_file(self): + def edit_file(self, file=None): """Calls execute_file with the current file and app='editor'""" - if self.env.cf is None: + if file is None: + file = self.env.cf + elif isinstance(file, str): + file = File(os.path.expanduser(file)) + if file is None: return - self.execute_file(self.env.cf, app = 'editor') + self.execute_file(file, app = 'editor') def open_console(self, mode=':', string=''): """Open the console if the current UI supports that""" diff --git a/ranger/commands.py b/ranger/commands.py index a62caf60..411408eb 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -271,6 +271,18 @@ class mkdir(Command): pass +class edit(Command): + """ + :edit <filename> + + Opens the specified file in vim + """ + + def execute(self): + line = parse(self.line) + self.fm.edit_file(line.rest(1)) + + class rename(Command): """ :rename <newname> @@ -371,6 +383,7 @@ def alias(**kw): by_name[key] = value alias(q=quit) +alias(e=quit) def command_generator(start): return (cmd + ' ' for cmd in by_name if cmd.startswith(start)) |