From 854369afade13299ad2c91eff20d32c4e6a3ce4f Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Sun, 26 Nov 2023 12:36:42 +0100 Subject: [PATCH] Add a 'user' command, analogous to 'root' but jumps to a pubnix user's capsule if the URL starts with ~username. --- src/av98/client.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/av98/client.py b/src/av98/client.py index 56509e6e..b5c60363 100755 --- a/src/av98/client.py +++ b/src/av98/client.py @@ -122,6 +122,13 @@ class GeminiItem(): def root(self): return GeminiItem(self._derive_url("/")) + def user(self): + if not self.path.startswith("/~"): + raise ValueError("This is not a tilde URL.") + new_path = self.path.split("/")[1] + "/" + print(new_path) + return GeminiItem(self._derive_url(new_path)) + def up(self): pathbits = list(os.path.split(self.path.rstrip('/'))) # Don't try to go higher than root @@ -1046,6 +1053,14 @@ Slow internet connection? Use 'set timeout' to be more patient.""") """Go to root selector of the server hosting current item.""" self._go_to_gi(self.gi.root()) + @needs_gi + def do_user(self, *args): + """If the current URL has a leading ~user/ component, go to its root.""" + try: + self._go_to_gi(self.gi.user()) + except ValueError: + print("The current URL does not appear to start with a tilde dir.") + def do_back(self, *args): """Go back to the previous gemini item.""" if not self.history or self.hist_index == 0: