Created
September 21, 2023 09:20
-
-
Save mping-exo/aef4765b0edb41f5c8bc08c8d8397b27 to your computer and use it in GitHub Desktop.
Kitty highlighter
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
from kitty.clipboard import set_clipboard_string, set_primary_selection | |
import re | |
def mark(text, args, Mark, extra_cli_args, *a): | |
# This function is responsible for finding all | |
# matching text. extra_cli_args are any extra arguments | |
# passed on the command line when invoking the kitten. | |
# We mark all individual word for potential selection | |
for idx, m in enumerate(re.finditer(r'[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)', text)): | |
start, end = m.span() | |
mark_text = text[start:end].replace('\n', '').replace('\0', '') | |
# The empty dictionary below will be available as groupdicts | |
# in handle_result() and can contain arbitrary data. | |
yield Mark(idx, start, end, mark_text, {}) | |
def handle_result(args, data, target_window_id, boss, extra_cli_args, *a): | |
# This function is responsible for performing some | |
# action on the selected text. | |
# matches is a list of the selected entries and groupdicts contains | |
# the arbitrary data associated with each entry in mark() above | |
matches, groupdicts = [], [] | |
for m, g in zip(data['match'], data['groupdicts']): | |
if m: | |
matches.append(m), groupdicts.append(g) | |
for word, match_data in zip(matches, groupdicts): | |
# Lookup the word in a dictionary, the open_url function | |
# will open the provided url in the system browser | |
#boss.open_url(f'https://www.google.com/search?q=define:{word}') | |
set_clipboard_string(word) | |
# boss.copy_to_buffer('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
map f1 kitten hints --customize-processing custom-hints-uuid.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment