From 1fb848249e0a652c549569815ea97c424585b42a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 1 Apr 2015 22:30:46 +0200 Subject: [PATCH] Handle sessions starting with _ as internal. :session-{load,save,delete} now refuses to handle sessions starting with _, unless a new -f/--force parameter is given. --- doc/help/commands.asciidoc | 13 ++++++++++--- qutebrowser/misc/sessions.py | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 70c707def..3aafacc74 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -406,16 +406,20 @@ Search for a text on the current page. [[session-delete]] === session-delete -Syntax: +:session-delete 'name'+ +Syntax: +:session-delete [*--force*] 'name'+ Delete a session. ==== positional arguments * +'name'+: The name of the session. +==== optional arguments +* +*-f*+, +*--force*+: Force deleting internal sessions (starting with an underline). + + [[session-load]] === session-load -Syntax: +:session-load [*--clear*] 'name'+ +Syntax: +:session-load [*--clear*] [*--force*] 'name'+ Load a session. @@ -424,10 +428,12 @@ Load a session. ==== optional arguments * +*-c*+, +*--clear*+: Close all existing windows. +* +*-f*+, +*--force*+: Force loading internal sessions (starting with an underline). + [[session-save]] === session-save -Syntax: +:session-save [*--quiet*] ['name']+ +Syntax: +:session-save [*--quiet*] [*--force*] ['name']+ Save a session. @@ -436,6 +442,7 @@ Save a session. ==== optional arguments * +*-q*+, +*--quiet*+: Don't show confirmation message. +* +*-f*+, +*--force*+: Force saving internal sessions (starting with an underline). [[set]] === set diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py index 0e0c22b9e..921c889e1 100644 --- a/qutebrowser/misc/sessions.py +++ b/qutebrowser/misc/sessions.py @@ -261,13 +261,18 @@ class SessionManager(QObject): @cmdutils.register(completion=[usertypes.Completion.sessions], instance='session-manager') - def session_load(self, name, clear=False): + def session_load(self, name, clear=False, force=False): """Load a session. Args: name: The name of the session. clear: Close all existing windows. + force: Force loading internal sessions (starting with an + underline). """ + if name.startswith('_') and not force: + raise cmdexc.CommandError("{!r} is an internal session, use " + "--force to load anyways.".format(name)) old_windows = list(objreg.window_registry.values()) try: self.load(name) @@ -285,14 +290,18 @@ class SessionManager(QObject): completion=[usertypes.Completion.sessions], instance='session-manager') def session_save(self, win_id: {'special': 'win_id'}, name='default', - quiet=False): + quiet=False, force=False): """Save a session. Args: win_id: The current window ID. name: The name of the session. quiet: Don't show confirmation message. + force: Force saving internal sessions (starting with an underline). """ + if name.startswith('_') and not force: + raise cmdexc.CommandError("{!r} is an internal session, use " + "--force to save anyways.".format(name)) try: self.save(name) except SessionError as e: @@ -305,12 +314,18 @@ class SessionManager(QObject): @cmdutils.register(completion=[usertypes.Completion.sessions], instance='session-manager') - def session_delete(self, name): + def session_delete(self, name, force=False): """Delete a session. Args: name: The name of the session. + force: Force deleting internal sessions (starting with an + underline). """ + if name.startswith('_') and not force: + raise cmdexc.CommandError("{!r} is an internal session, use " + "--force to delete anyways.".format( + name)) try: self.delete(name) except OSError as e: