diff --git a/qutebrowser/app.py b/qutebrowser/app.py index f499f1be7..d2104e554 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -77,6 +77,7 @@ class QuteBrowser(QApplication): 'scrollstart': self.mainwindow.tabs.scroll_start_act, 'scrollend': self.mainwindow.tabs.scroll_end_act, 'undo': self.mainwindow.tabs.undo_close, + 'pyeval': self.pyeval } handler = handlers[cmd] @@ -86,3 +87,14 @@ class QuteBrowser(QApplication): handler(*args, count=count) else: handler(*args) + + def pyeval(self, s): + try: + r = eval(s) + out = repr(r) + except Exception as e: + out = ': '.join([e.__class__.__name__, str(e)]) + + tab = self.mainwindow.tabs.currentWidget() + tab.setContent(out.encode('UTF-8'), 'text/plain') + diff --git a/qutebrowser/commands/commands.py b/qutebrowser/commands/commands.py index 808cc1621..412deca49 100644 --- a/qutebrowser/commands/commands.py +++ b/qutebrowser/commands/commands.py @@ -75,3 +75,7 @@ class ScrollStart(Command): class ScrollEnd(Command): nargs = 0 key = 'G' + +class PyEval(Command): + nargs = 1 + split_args = False