Skip to content

Instantly share code, notes, and snippets.

@firstworldproblems
Created June 24, 2017 04:11
Show Gist options
  • Save firstworldproblems/74d6f826096a2c491904f7a4f8e2f951 to your computer and use it in GitHub Desktop.
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.
#!/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