From 33dff703574e1c4b90906140c2f217cf7823e098 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 30 Mar 2015 07:09:16 +0200 Subject: [PATCH] :session-load: Add a -c/--clear argument. See #523. --- doc/help/commands.asciidoc | 5 ++++- qutebrowser/misc/sessions.py | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index a2eb1ded9..11cd85198 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -414,13 +414,16 @@ Delete a session. [[session-load]] === session-load -Syntax: +:session-load 'name'+ +Syntax: +:session-load [*--clear*] 'name'+ Load a session. ==== positional arguments * +'name'+: The name of the session. +==== optional arguments +* +*-c*+, +*--clear*+: Close all existing windows. + [[session-save]] === session-save Syntax: +:session-save [*--quiet*] ['name']+ diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py index 7db608480..45ddeabd2 100644 --- a/qutebrowser/misc/sessions.py +++ b/qutebrowser/misc/sessions.py @@ -266,12 +266,14 @@ class SessionManager(QObject): @cmdutils.register(completion=[usertypes.Completion.sessions], instance='session-manager') - def session_load(self, name): + def session_load(self, name, clear=False): """Load a session. Args: name: The name of the session. + clear: Close all existing windows. """ + old_windows = list(objreg.window_registry.values()) try: self.load(name) except SessionNotFoundError: @@ -279,6 +281,10 @@ class SessionManager(QObject): except SessionError as e: raise cmdexc.CommandError("Error while loading session: {}" .format(e)) + else: + if clear: + for win in old_windows: + win.close() @cmdutils.register(name=['session-save', 'w'], completion=[usertypes.Completion.sessions],