From c3ce167926b3cc476ef1c6b8606b872891e8a419 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 30 Jan 2014 20:41:54 +0100 Subject: [PATCH] Allow commands/URLs to be passed as arguments. --- qutebrowser/app.py | 27 +++++++++++++++++++++++++++ qutebrowser/utils/config.py | 1 + qutebrowser/widgets/browser.py | 3 +-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 78a0d12f8..f23322809 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -83,6 +83,29 @@ class QuteBrowser(QApplication): self.mainwindow.show() self._python_hacks() + self._process_init_args() + + def _process_init_args(self): + """Process initial positional args. + + URLs to open have no prefix, commands to execute begin with a colon. + """ + opened_urls = False + + for e in self.args.command: + if e.startswith(':'): + logging.debug('Startup cmd {}'.format(e)) + self.commandparser.run(e.lstrip(':')) + else: + logging.debug('Startup url {}'.format(e)) + opened_urls = True + self.mainwindow.tabs.tabopen(e) + + if not opened_urls: + logging.debug('Opening startpage') + for url in config.config.get('general', 'startpage', + fallback='http://ddg.gg/').split(','): + self.mainwindow.tabs.tabopen(url) def _tmp_exception_hook(self, exctype, value, traceback): """Handle exceptions while initializing by simply exiting. @@ -132,6 +155,10 @@ class QuteBrowser(QApplication): help='Set loglevel', default='info') parser.add_argument('-c', '--confdir', help='Set config directory ' '(empty for no config storage)') + parser.add_argument('command', nargs='*', help='Commands to execute ' + 'on startup.', metavar=':command') + # URLs will actually be in command + parser.add_argument('url', nargs='*', help='URLs to open on startup.') self.args = parser.parse_args() def _initlog(self): diff --git a/qutebrowser/utils/config.py b/qutebrowser/utils/config.py index 62b39cef6..237d9db91 100644 --- a/qutebrowser/utils/config.py +++ b/qutebrowser/utils/config.py @@ -20,6 +20,7 @@ default_config = """ space_scroll = 200 ignorecase = true wrapsearch = true + startpage = http://www.duckduckgo.com/ [keybind] o = open diff --git a/qutebrowser/widgets/browser.py b/qutebrowser/widgets/browser.py index a8f280982..a66cf6779 100644 --- a/qutebrowser/widgets/browser.py +++ b/qutebrowser/widgets/browser.py @@ -8,7 +8,7 @@ containing BrowserTabs). import logging from PyQt5.QtWidgets import QShortcut, QApplication -from PyQt5.QtCore import QUrl, pyqtSignal, Qt, QEvent +from PyQt5.QtCore import pyqtSignal, Qt, QEvent from PyQt5.QtGui import QClipboard from PyQt5.QtPrintSupport import QPrintPreviewDialog from PyQt5.QtWebKitWidgets import QWebView, QWebPage @@ -39,7 +39,6 @@ class TabbedBrowser(TabWidget): def __init__(self, parent): super().__init__(parent) self.currentChanged.connect(self._currentChanged_handler) - self.tabopen(QUrl("http://ddg.gg/")) space = QShortcut(self) space.setKey(Qt.Key_Space) space.setContext(Qt.WidgetWithChildrenShortcut)