new feature: go automatically fetch content from clipboard if xsel is installed
This commit is contained in:
parent
256c28e916
commit
16cde598c4
31
av98.py
31
av98.py
|
@ -249,7 +249,9 @@ CRLF = '\r\n'
|
||||||
|
|
||||||
# Cheap and cheerful URL detector
|
# Cheap and cheerful URL detector
|
||||||
def looks_like_url(word):
|
def looks_like_url(word):
|
||||||
return "." in word and word.startswith("gemini://")
|
start = word.startswith("gemini://") or word.startswith("http://")\
|
||||||
|
or word.startswith("https://")
|
||||||
|
return "." in word and start
|
||||||
|
|
||||||
class UserAbortException(Exception):
|
class UserAbortException(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -1235,9 +1237,7 @@ you'll be able to transparently follow links to Gopherspace!""")
|
||||||
return self.do_up()
|
return self.do_up()
|
||||||
elif line.startswith("/"):
|
elif line.startswith("/"):
|
||||||
return self.do_search(line[1:])
|
return self.do_search(line[1:])
|
||||||
elif line.startswith("http://") or line.startswith("https://"):
|
elif looks_like_url(line):
|
||||||
return self.do_go(line)
|
|
||||||
elif line.startswith("gemini://"):
|
|
||||||
return self.do_go(line)
|
return self.do_go(line)
|
||||||
|
|
||||||
# Expand abbreviated commands
|
# Expand abbreviated commands
|
||||||
|
@ -1385,7 +1385,28 @@ you'll be able to transparently follow links to Gopherspace!""")
|
||||||
"""Go to a gemini URL or marked item."""
|
"""Go to a gemini URL or marked item."""
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line:
|
if not line:
|
||||||
print("Go where?")
|
if shutil.which('xsel'):
|
||||||
|
clipboards = []
|
||||||
|
urls = []
|
||||||
|
clipboards.append(subprocess.check_output(['xsel','-p'],text=True))
|
||||||
|
clipboards.append(subprocess.check_output(['xsel','-s'],text=True))
|
||||||
|
clipboards.append(subprocess.check_output(['xsel','-b'],text=True))
|
||||||
|
for u in clipboards:
|
||||||
|
if looks_like_url(u) :
|
||||||
|
urls.append(u)
|
||||||
|
if len(urls) > 1:
|
||||||
|
self.lookup = []
|
||||||
|
for u in urls:
|
||||||
|
self.lookup.append(GeminiItem(u))
|
||||||
|
print("Where do you want to go today?")
|
||||||
|
self._show_lookup()
|
||||||
|
elif len(urls) == 1:
|
||||||
|
self.do_go(urls[0])
|
||||||
|
else:
|
||||||
|
print("Go where? (hint: simply copy an URL)")
|
||||||
|
else:
|
||||||
|
print("Go where? (hint: install xsel to go to copied URLs)")
|
||||||
|
|
||||||
# First, check for possible marks
|
# First, check for possible marks
|
||||||
elif line in self.marks:
|
elif line in self.marks:
|
||||||
gi = self.marks[line]
|
gi = self.marks[line]
|
||||||
|
|
Loading…
Reference in New Issue