Created
June 24, 2017 04:11
-
-
Save firstworldproblems/74d6f826096a2c491904f7a4f8e2f951 to your computer and use it in GitHub Desktop.
Fix for Ubuntu builds prefixing file:// to file paths when pasting into terminal from clipboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Fix for Ubuntu builds prefixing file:// to file paths when pasting into terminal from clipboard. | |
# By faustus (2017) | |
# https://gist.github.com/firstworldproblems/74d6f826096a2c491904f7a4f8e2f951 | |
import os | |
import pyperclip | |
import time | |
class ClipboardWatcher(): | |
def __init__(self,latency): | |
self.clipboard_last = pyperclip.paste() | |
self.clipboard_now = None | |
self.latency = latency | |
def check_clipboard(self): | |
# assume clipboard is space delimited list of valid paths | |
as_list = self.clipboard_now.split() | |
valid_path = [ i for i in as_list if os.path.exists(i) ] | |
if len(as_list) == len(valid_path): # assumption true | |
self.clipboard_now = " ".join(valid_path) | |
return True | |
return False | |
def run(self): | |
while True: | |
time.sleep(self.latency) | |
self.clipboard_now = pyperclip.paste() | |
if self.clipboard_now != self.clipboard_last: | |
if self.check_clipboard(): | |
pyperclip.copy(self.clipboard_now) | |
print "Matched:", self.clipboard_now | |
self.clipboard_last = self.clipboard_now | |
clippy = ClipboardWatcher(1) # watch every n seconds | |
clippy.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment