-
Notifications
You must be signed in to change notification settings - Fork 150
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
Package star-rating for Espanso #157
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
A small script package with a single trigger and no apparently malicious code. A couple of minor changes required to rename readme.md
, and correct _manifest.yml
(or change the name of the package).
As the script is so short, I would suggest setting it inline rather than including a separate file, e.g.:
- regex: :st(?P<fstars>\d+),(?P<estars>\d+)
replace: "{{stars}}"
vars:
- name: stars
type: script
params:
args:
- python
- -c
- |
import sys, codecs
# Ensure UTF-8 output
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
print(chr(0x2605)*{{fstars}}+chr(0x2606)*{{estars}})
- I have removed the double-quotes around the
regex:
to obviate the need to escape the backslashes. - Without a terminating character, the final
+
in theregex:
string is redundant as it'll always match a single digit - The error-checking, and
int
float
conversions aren't required because theregex:
won't trigger at all if the text following:st
doesn't consist of two integers separated by a comma. - I note the UTF-8 configuration doesn't match that suggested in the docs, but perhaps you want to ensure it'll work with versions of Python pre-3.7.
- The final line could be
print('★' * {{fstars}} + '☆' * {{estars}})
for clarity, but it's a personal choice.
Minor edit
A new package Espanso; display a star-rating anywhere you want.