diff options
author | hut <hut@lavabit.com> | 2010-02-17 15:32:53 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-02-19 00:40:11 +0100 |
commit | 014c41843fa326d7f8163ceca4fa7b99c4d3dd91 (patch) | |
tree | 494c7f1d4e47736de21f3a32631381f10778112e | |
parent | 8a894508e5ea51996ee9d8523a1cbfc88a6a1eae (diff) | |
download | ranger-014c41843fa326d7f8163ceca4fa7b99c4d3dd91.tar.gz |
commands: added an eval function + documentation
-rw-r--r-- | ranger/commands.py | 31 | ||||
-rw-r--r-- | ranger/help/console.py | 4 |
2 files changed, 35 insertions, 0 deletions
diff --git a/ranger/commands.py b/ranger/commands.py index a6fc77fb..b3625037 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -315,6 +315,37 @@ class edit(Command): return self._tab_directory_content() +class eval_(Command): + """ + :eval <python code> + + Evaluates the python code. + `fm' is a reference to the FM instance. + To display text, use the function `p'. + + Examples: + :eval fm + :eval len(fm.env.directories) + :eval p("Hello World!") + """ + name = 'eval' + + def execute(self): + code = parse(self.line).rest(1) + fm = self.fm + p = fm.notify + try: + try: + result = eval(code) + except SyntaxError: + exec(code) + else: + if result: + p(result) + except Exception as err: + p(err) + + class rename(Command): """ :rename <newname> diff --git a/ranger/help/console.py b/ranger/help/console.py index 1ea06f90..cd382d2e 100644 --- a/ranger/help/console.py +++ b/ranger/help/console.py @@ -77,6 +77,10 @@ it conflicts with ":cd". :edit <filename> Opens the specified file in the text editor. +:eval <python_code> + Evaluates the given code inside ranger. `fm' is a reference to + the filemanager instance, `p' is a function to print text. + :filter <string> Displays only files which contain <string> in their basename. |