Add a 'user' command, analogous to 'root' but jumps to a pubnix user's capsule if the URL starts with ~username.

This commit is contained in:
Solderpunk 2023-11-26 12:36:42 +01:00
parent 0e9953882c
commit 854369afad
1 changed files with 15 additions and 0 deletions

View File

@ -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: