Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Greenclip plugin #192

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions greenclip/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
Inline codespace launcher.
"""

from albert import *
import subprocess
from pathlib import Path
from typing import List
from difflib import SequenceMatcher

md_iid = '2.0'
md_version = '1.0'
md_name = 'GreenClip'
md_description = 'Clipboard history for greenclip'
md_url = 'https://github.com/lawrencegripper/dotfiles'
md_lib_dependencies = []


def get_clipboard_history() -> List[str]:
command: str = "greenclip print"
response = subprocess.run(command.split(' '), capture_output=True)
return response.stdout.decode('utf-8').splitlines()


def score(query: TriggerQuery, item: Item) -> float:
return SequenceMatcher(None, item.text.lower(), query.string.lower()).ratio()

class Plugin(PluginInstance, TriggerQueryHandler):

def __init__(self):
TriggerQueryHandler.__init__(self,
id=md_id,
name=md_name,
description=md_description,
synopsis="<text in clipboard>",
defaultTrigger='cl ',
supportsFuzzyMatching=True)
PluginInstance.__init__(self, extensions=[self])
self.iconUrls = [f"file:{Path(__file__).parent}/clipboard.svg"]

def handleTriggerQuery(self, query):
items: List[Item] = []
stripped = query.string.strip()

for clip in get_clipboard_history():
items.append(
StandardItem(
id=md_id,
text=clip,
iconUrls=self.iconUrls,
actions=[
Action("paste", "Paste", lambda c=clip: setClipboardTextAndPaste(c)),
Action("set", "Set Clipboard", lambda c=clip: setClipboardText(c)),
Action("clearhistory", "Clear History", lambda: runTerminal(f'greenclip clear', close_on_exit=True)),
]
)
)
items.sort(key=lambda i: score(query, i), reverse=True)
for i in items:
query.add(i)
9 changes: 9 additions & 0 deletions greenclip/clipboard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.