Skip to content

Instantly share code, notes, and snippets.

@outloudvi
Created February 22, 2019 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save outloudvi/9d34fd0f518cb996d5883d962d203252 to your computer and use it in GitHub Desktop.
Save outloudvi/9d34fd0f518cb996d5883d962d203252 to your computer and use it in GitHub Desktop.
A wrapper for wudao-dict with the enhancement of notify-send.
#!/usr/bin/env python3
# You may want to link it to /usr/bin then KDE can use it.
import re
from subprocess import run, check_output, DEVNULL
import sys
ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
result = check_output(
['/usr/bin/wd','-s',sys.argv[1]]
).decode()
escaped = ansi_escape.sub('', result)
groups = escaped.split('\n')
run(
['notify-send',groups[0],'\n'.join(groups[1:])],
stdout=DEVNULL,
stderr=DEVNULL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment