Add command for generating fragment.

This commit is contained in:
nervuri 2021-12-25 14:47:43 +00:00
parent bb1c6ba643
commit b684c8d8b7
1 changed files with 17 additions and 0 deletions

17
av98.py
View File

@ -66,6 +66,7 @@ _ABBREVS = {
"book": "bookmarks",
"f": "fold",
"fo": "forward",
"fr": "fragment",
"g": "go",
"h": "history",
"hist": "history",
@ -1447,6 +1448,22 @@ Use 'ls -l' to see URLs."""
cmd_str = cmd_str % tmp_file
subprocess.call("%s | less %s" % (cmd_str, less_opt), shell=True)
@needs_gi
def do_fragment(self, *args):
"""Add search fragment to the current URI."""
err = """Please provide text to include in the fragment."""
if not self.mime == 'text/gemini':
print("Can't generate fragment for %s." % self.mime)
return
fragment_input = args[0]
if not fragment_input:
print(err)
return
# Percent-encode input, append as fragment and visit the new URI.
uri_without_fragment = self.gi.url.split('#')[0]
self.do_go(uri_without_fragment\
+ '#' + urllib.parse.quote(fragment_input))
@needs_gi
def do_fold(self, *args):
"""Run most recently visited item through "fold" command."""