From 7615e20091faca7343bdaa506a042777be11bd23 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 5 Feb 2015 07:54:19 +0100 Subject: [PATCH] Add -s argument to set temporary options. --- qutebrowser/app.py | 21 ++++++++++++++------- qutebrowser/misc/ipc.py | 2 +- qutebrowser/qutebrowser.py | 5 +++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index d03479854..e5a44ad1e 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -39,7 +39,7 @@ from PyQt5.QtCore import (pyqtSlot, qInstallMessageHandler, QTimer, QUrl, import qutebrowser import qutebrowser.resources # pylint: disable=unused-import from qutebrowser.commands import cmdutils, runners -from qutebrowser.config import style, config, websettings +from qutebrowser.config import style, config, websettings, configexc from qutebrowser.browser import quickmarks, cookies, cache, adblock, history from qutebrowser.browser.network import qutescheme, proxy from qutebrowser.mainwindow import mainwindow @@ -136,7 +136,7 @@ class Application(QApplication): "Error while initializing: {}".format(e)) msgbox.exec_() sys.exit(1) - QTimer.singleShot(0, self._open_pages) + QTimer.singleShot(0, self._process_args) log.init.debug("Initializing eventfilter...") self._event_filter = modeman.EventFilter(self) @@ -252,14 +252,21 @@ class Application(QApplication): else: earlyinit.init_faulthandler(self._crashlogfile) - def _open_pages(self): + def _process_args(self): """Open startpage etc. and process commandline args.""" - self.process_args(self._args.command) + config_obj = objreg.get('config') + for sect, opt, val in self._args.temp_settings: + try: + config_obj.set('temp', sect, opt, val) + except (configexc.Error, configparser.Error) as e: + message.error('current', "set: {} - {}".format( + e.__class__.__name__, e)) + self.process_pos_args(self._args.command) self._open_startpage() self._open_quickstart() def _get_window(self, via_ipc, force_window=False, force_tab=False): - """Helper function for process_args to get a window id. + """Helper function for process_pos_args to get a window id. Args: via_ipc: Whether the request was made via IPC. @@ -299,8 +306,8 @@ class Application(QApplication): self.alert(window_to_raise) return win_id - def process_args(self, args, via_ipc=False, cwd=None): - """Process commandline args. + def process_pos_args(self, args, via_ipc=False, cwd=None): + """Process positional commandline args. URLs to open have no prefix, commands to execute begin with a colon. diff --git a/qutebrowser/misc/ipc.py b/qutebrowser/misc/ipc.py index 9039158ff..897f1294c 100644 --- a/qutebrowser/misc/ipc.py +++ b/qutebrowser/misc/ipc.py @@ -158,7 +158,7 @@ class IPCServer(QObject): return cwd = json_data.get('cwd', None) app = objreg.get('app') - app.process_args(args, via_ipc=True, cwd=cwd) + app.process_pos_args(args, via_ipc=True, cwd=cwd) @pyqtSlot() def on_timeout(self): diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py index 73d75ddec..794b7a015 100644 --- a/qutebrowser/qutebrowser.py +++ b/qutebrowser/qutebrowser.py @@ -49,6 +49,11 @@ def get_argparser(): "for no config storage)") parser.add_argument('-V', '--version', help="Show version and quit.", action='store_true') + parser.add_argument('-s', '--set', help="Set a temporary setting for " + "this session", nargs=3, action='append', + dest='temp_settings', default=[], + metavar=('SECTION', 'OPTION', 'VALUE')) + debug = parser.add_argument_group('debug arguments') debug.add_argument('-l', '--loglevel', dest='loglevel', help="Set loglevel", default='info')