cp url X to copy the url of a link

This commit is contained in:
Lionel Dricot 2022-03-15 23:43:21 +01:00
parent 4f4e1cc72c
commit 03f62d2e57
2 changed files with 10 additions and 2 deletions

View File

@ -1,7 +1,9 @@
# Offpunk History
## 1.1 - Unreleased
- Perfect rendering of pictures with chafa 1.8+ and compatible terminal
- "cp cache" put the path of the cached content in clipboard
- "cp url X" will copy the URL of link X (suggested by Eoin Carney)
- HTML renderering of <pre> has been improved
- "fold" has been removed as it doesnt work well anyway with our width.
- Fixed crash when chafa is not installed (Thanks Xavier Hinault for the report)

View File

@ -2589,15 +2589,21 @@ class GeminiClient(cmd.Cmd):
else:
print("Already online. Try offline.")
def do_copy(self, *args):
def do_copy(self, arg):
"""Copy the content of the last visited page as gemtext in the clipboard.
Use with "url" as argument to only copy the adress.
Use with "raw" to copy ANSI content as seen in your terminal (not gemtext).
Use with "cache" to copy the path of the cached content."""
if self.gi:
if _HAS_XSEL:
args = arg.split()
if args and args[0] == "url":
subprocess.call(("echo %s |xsel -b -i" % self.gi.url), shell=True)
if len(args) > 1 and args[1].isdecimal():
gi = self.index[int(args[1])-1]
url = gi.url
else:
url = self.gi.url
subprocess.call(("echo %s |xsel -b -i" % url), shell=True)
elif args and args[0] == "raw":
subprocess.call(("cat %s |xsel -b -i" % self.gi.get_temp_filename()), shell=True)
elif args and args[0] == "cache":