diff --git a/rtv/docs.py b/rtv/docs.py index 49f9c1f..e07f882 100644 --- a/rtv/docs.py +++ b/rtv/docs.py @@ -57,6 +57,8 @@ https://github.com/michael-lazar/rtv o : Open the submission or comment url SPACE : Fold or expand the selected comment tree b : Display urls with urlview + y : Copy submission permalink to clipboard + Y : Copy submission link to clipboard [Prompt] The `/` prompt accepts subreddits in the following formats diff --git a/rtv/page.py b/rtv/page.py index 1d400d1..2ecd556 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -5,6 +5,7 @@ import os import sys import time import curses +import pyperclip from functools import wraps import six @@ -318,6 +319,28 @@ class Page(object): message = 'New Messages' if inbox > 0 else 'No New Messages' self.term.show_notification(message) + @PageController.register(Command('COPY_SUBMISSION_PERMALINK')) + def copy_submission_permalink(self): + """ + Copies submission permalink to OS clipboard + """ + + data = self.get_selected_item() + url = data.get('permalink') + if url is not None: + pyperclip.copy(url) + + @PageController.register(Command('COPY_SUBMISSION_URL')) + def copy_post_permalink(self): + """ + Copies submission url to OS clipboard + """ + + data = self.get_selected_item() + url = data.get('url') + if url is not None: + pyperclip.copy(url) + def clear_input_queue(self): """ Clear excessive input caused by the scroll wheel or holding down a key diff --git a/rtv/templates/rtv.cfg b/rtv/templates/rtv.cfg index 7395d1c..3de6cbc 100644 --- a/rtv/templates/rtv.cfg +++ b/rtv/templates/rtv.cfg @@ -118,6 +118,8 @@ INBOX = i REFRESH = r, PROMPT = / SAVE = w +COPY_SUBMISSION_PERMALINK = y +COPY_SUBMISSION_URL = Y ; Submission page SUBMISSION_TOGGLE_COMMENT = 0x20 diff --git a/setup.py b/setup.py index ce0eb00..1fb777f 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,7 @@ install_requires = [ 'kitchen', 'requests >=2.4.0', # https://github.com/michael-lazar/rtv/issues/325 'six', + 'pyperclip' ] tests_require = [