-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefers python3 if available, which is the default on Monterey. Fallsback to plain python (2) if available. Script should work on both. Updates icon to work better with dark themes.
- Loading branch information
1 parent
64eb341
commit 3d9eb58
Showing
14 changed files
with
129 additions
and
38 deletions.
There are no files selected for viewing
Binary file not shown.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,79 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
import re, sys | ||
from __future__ import print_function | ||
import re | ||
import sys | ||
from xml.sax.saxutils import escape | ||
from titlecase import titlecase | ||
|
||
if len(sys.argv) > 1 and len(sys.argv[1].strip()): | ||
text = sys.argv[1] | ||
text = sys.argv[1] | ||
else: | ||
text = sys.stdin.read() | ||
text = sys.stdin.read() | ||
|
||
if len(text.strip()) == 0: | ||
sys.exit(0) | ||
|
||
always_uppercase = r'''\bXML|HTML|CSS|JSON|FYI|AOL|ATM|BBC|CD|FAQ|GAIM|GNU|GTK|HIRD|HIV | ||
|HURD|IEEE|IOU|IRA|IUPAC|JPEG|LCD|NAACP|NAC|NATO|NCAA|NOAD|OEM|PHP|ROM|SAT|SFMOMA|SQL|USA|VHDL|VHSIC|W3C | ||
|LOL|WTF\b''' | ||
always_uppercase_re = re.compile(always_uppercase, re.I | re.X) | ||
|
||
|
||
def titlecase_plus(text): | ||
"""The titlecase module assumes words in all UPPERCASE should be ignored. | ||
This works for words like HTML, FYI, ID, etc., but not generally. Just work | ||
around for now by going to .lower first. Then, replace any well known | ||
"always" uppercase""" | ||
text = titlecase(text.lower()) | ||
def upcase(m): | ||
return m.group().upper() | ||
return always_uppercase_re.sub(upcase, text) | ||
"""The titlecase module assumes words in all UPPERCASE should be ignored. | ||
This works for words like HTML, FYI, ID, etc., but not generally. Just work | ||
around for now by going to .lower first. Then, replace any well known | ||
"always" uppercase""" | ||
text = titlecase(text.lower()) | ||
|
||
def upcase(m): | ||
return m.group().upper() | ||
return always_uppercase_re.sub(upcase, text) | ||
|
||
|
||
variations = { | ||
'lower': escape(text.lower(), {'"': '"', '\n': ' '} ), | ||
'upper': escape(text.upper(), {'"': '"', '\n': ' '} ), | ||
'title': escape(titlecase_plus(text), {'"': '"', '\n': ' '} ), | ||
'camel': escape(titlecase_plus(text), {'"': '"', '\n': ' '} ).replace(' ', ''), | ||
'kebab': escape(text.lower(), {'"': '"', '\n': ' '} ).replace(' ', '-').replace('_', '-'), | ||
'snake': escape(text.lower(), {'"': '"', '\n': ' '} ).replace(' ', '_').replace('-', '_') | ||
'lower': escape(text.lower(), {'"': '"', '\n': ' '}), | ||
'upper': escape(text.upper(), {'"': '"', '\n': ' '}), | ||
'title': escape(titlecase_plus(text), {'"': '"', '\n': ' '}), | ||
'camel': escape(text.title(), {'"': '"', '\n': ' '}).replace(' ', ''), | ||
'kebab': escape(text.lower(), {'"': '"', '\n': ' '}).replace(' ', '-').replace('_', '-'), | ||
'snake': escape(text.lower(), {'"': '"', '\n': ' '}).replace(' ', '_').replace('-', '_') | ||
|
||
} | ||
|
||
print """<?xml version="1.0"?> | ||
print("""<?xml version="1.0"?> | ||
<items> | ||
<item arg="%(lower)s"> | ||
<title>%(lower)s</title> | ||
<subtitle>lowercase</subtitle> | ||
<subtitle>Transform text to `lowercase`</subtitle> | ||
<icon>lowercase.png</icon> | ||
</item> | ||
<item arg="%(upper)s"> | ||
<title>%(upper)s</title> | ||
<subtitle>UPPERCASE</subtitle> | ||
<subtitle>Transform text to `UPPERCASE`</subtitle> | ||
<icon>uppercase.png</icon> | ||
</item> | ||
<item arg="%(title)s"> | ||
<title>%(title)s</title> | ||
<subtitle>Title Case</subtitle> | ||
<subtitle>Transform text to `Title Case`</subtitle> | ||
<icon>titlecase.png</icon> | ||
</item> | ||
<item arg="%(camel)s"> | ||
<title>%(camel)s</title> | ||
<subtitle>CamelCase</subtitle> | ||
<subtitle>Transform text to `CamelCase`</subtitle> | ||
<icon>camelcase.png</icon> | ||
</item> | ||
<item arg="%(kebab)s"> | ||
<title>%(kebab)s</title> | ||
<subtitle>kebab-case</subtitle> | ||
<subtitle>Transform text to hyphenated `kebab-case`</subtitle> | ||
<icon>kebabcase.png</icon> | ||
</item> | ||
<item arg="%(snake)s"> | ||
<title>%(snake)s</title> | ||
<subtitle>snake_case</subtitle> | ||
<subtitle>Transform text to `snake_case`</subtitle> | ||
<icon>snakecase.png</icon> | ||
</item> | ||
</items>""" % variations | ||
</items>""" % variations) |
Binary file not shown.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.