diff options
author | hut <hut@lavabit.com> | 2011-09-30 01:43:27 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-09-30 01:46:09 +0200 |
commit | b1d25114617f41538f1e9e1740229f5e326c9f88 (patch) | |
tree | 5fe8b438759ea2a9a6495e57d7266a7bd36f340a /ranger/core | |
parent | 5e41c8479cfba986f6dad0e68aed3c1d7b51d3ae (diff) | |
download | ranger-b1d25114617f41538f1e9e1740229f5e326c9f88.tar.gz |
define keybindings in rc.conf (list of commands, loaded on startup)
Diffstat (limited to 'ranger/core')
-rw-r--r-- | ranger/core/actions.py | 40 | ||||
-rw-r--r-- | ranger/core/helper.py | 26 |
2 files changed, 48 insertions, 18 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 96e23189..0314888d 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -70,7 +70,19 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): bad = True text = str(text) self.log.appendleft(text) - self.ui.status.notify(text, duration=duration, bad=bad) + if self.ui and self.ui.is_on: + self.ui.status.notify(text, duration=duration, bad=bad) + else: + print(text) + + def abort(self): + try: + item = self.loader.queue[0] + except: + self.notify("Type Q or :quit<Enter> to exit Ranger") + else: + self.notify("Aborting: " + item.get_description()) + self.loader.remove(index=0) def redraw_window(self): """Redraw the window""" @@ -78,14 +90,20 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): def open_console(self, string='', prompt=None, position=None): """Open the console if the current UI supports that""" - if hasattr(self.ui, 'open_console'): - self.ui.open_console(string, prompt=prompt, position=position) + self.ui.open_console(string, prompt=prompt, position=position) def execute_console(self, string=''): """Execute a command for the console""" - self.open_console(string=string) - self.ui.console.line = string - self.ui.console.execute() + command_name = string.split()[0] + try: + cmd_class = self.commands.get_command(command_name) + except: + self.notify("Command not found: `%s'" % command_name) + else: + try: + cmd_class(string).execute() + except Exception as error: + self.notify(error) def substitute_macros(self, string): return _MacroTemplate(string).safe_substitute(self._get_macros()) @@ -149,6 +167,16 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): return macros + def source_cmdlist(self, filename, narg=None): + for line in open(filename, 'r'): + line = line.rstrip("\r\n") + try: + self.execute_console(line) + except Exception as e: + if ranger.arg.debug: + raise + else: + self.notify('Error in line `%s\':\n %s' % (line, str(e)), bad=True) def execute_file(self, files, **kw): """Execute a file. diff --git a/ranger/core/helper.py b/ranger/core/helper.py index 910c0241..62ab9091 100644 --- a/ranger/core/helper.py +++ b/ranger/core/helper.py @@ -103,22 +103,27 @@ def load_settings(fm, clean): pass from ranger.defaults import commands comcont.load_commands_from_module(commands) - commands = comcont + fm.commands = comcont # Load apps try: import apps except ImportError: from ranger.defaults import apps + fm.apps = apps.CustomApplications() - # Load keys + # Setup keymanager keymanager = ranger.core.shared.EnvironmentAware.env.keymanager ranger.api.keys.keymanager = keymanager - from ranger.defaults import keys - try: - import keys - except ImportError: - pass + + # Load rc.conf + conf = fm.confpath('rc.conf') + if os.access(conf, os.R_OK): + fm.source_cmdlist(conf) + if fm.settings.load_default_rc: + conf = fm.relpath('defaults', 'rc.conf') + if os.access(conf, os.R_OK): + fm.source_cmdlist(conf) # Load plugins try: @@ -148,15 +153,12 @@ def load_settings(fm, clean): else: comcont = ranger.api.commands.CommandContainer() ranger.api.commands.alias = comcont.alias - from ranger.api import keys keymanager = ranger.core.shared.EnvironmentAware.env.keymanager ranger.api.keys.keymanager = keymanager from ranger.defaults import commands, keys, apps comcont.load_commands_from_module(commands) - commands = comcont - fm.commands = commands - fm.keys = keys - fm.apps = apps.CustomApplications() + fm.commands = comcont + fm.apps = apps.CustomApplications() def load_apps(fm, clean): |