summaryrefslogtreecommitdiff
path: root/mac/.config/qutebrowser/userscripts/code_select
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-09-11 17:28:34 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-09-11 17:28:34 +0900
commitfc3af8a3b3af5e3cd35c9c6b075e71e9ce43eb69 (patch)
tree140aa5e044dc46cbcf4c9b1ea5978dd1899e5608 /mac/.config/qutebrowser/userscripts/code_select
parent53f239bf8067e4dda550d947e2a6b93de0c7dd65 (diff)
updates
Diffstat (limited to 'mac/.config/qutebrowser/userscripts/code_select')
-rwxr-xr-xmac/.config/qutebrowser/userscripts/code_select64
1 files changed, 0 insertions, 64 deletions
diff --git a/mac/.config/qutebrowser/userscripts/code_select b/mac/.config/qutebrowser/userscripts/code_select
deleted file mode 100755
index 8f7fc31..0000000
--- a/mac/.config/qutebrowser/userscripts/code_select
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env python3
-
-import os
-import html
-import re
-import sys
-import xml.etree.ElementTree as ET
-try:
- import pyperclip
-except ImportError:
- try:
- import pyclip as pyperclip
- except ImportError:
- PYPERCLIP = False
- else:
- PYPERCLIP = True
-else:
- PYPERCLIP = True
-
-
-def parse_text_content(element):
- # https://stackoverflow.com/a/35591507/15245191
- magic = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
- <!ENTITY nbsp ' '>
- ]>'''
- root = ET.fromstring(magic + element)
- text = ET.tostring(root, encoding="unicode", method="text")
- text = html.unescape(text)
- return text
-
-
-def send_command_to_qute(command):
- with open(os.environ.get("QUTE_FIFO"), "w") as f:
- f.write(command)
-
-
-def main():
- delimiter = sys.argv[1] if len(sys.argv) > 1 else ";"
- # For info on qute environment vairables, see
- # https://github.com/qutebrowser/qutebrowser/blob/master/doc/userscripts.asciidoc
- element = os.environ.get("QUTE_SELECTED_HTML")
- code_text = parse_text_content(element)
- re_remove_dollars = re.compile(r"^(\$ )", re.MULTILINE)
- code_text = re.sub(re_remove_dollars, '', code_text)
- if PYPERCLIP:
- pyperclip.copy(code_text)
- send_command_to_qute(
- "message-info 'copied to clipboard: {info}{suffix}'".format(
- info=code_text.splitlines()[0].replace("'", "\""),
- suffix="..." if len(code_text.splitlines()) > 1 else ""
- )
- )
- else:
- # Qute's yank command won't copy accross multiple lines so we
- # compromise by placing lines on a single line seperated by the
- # specified delimiter
- code_text = re.sub("(\n)+", delimiter, code_text)
- code_text = code_text.replace("'", "\"")
- send_command_to_qute("yank inline '{code}'\n".format(code=code_text))
-
-
-if __name__ == "__main__":
- main()