Skip to content

Commit f87b29d

Browse files
Przemysław Wrzesińskidehesa
authored andcommitted
Allowed conversion from CamelCase to snake_case
1 parent a770b25 commit f87b29d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

commands/conversions/change-case/snakecase.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# @raycast.description Change to clipboard text to snake case
1818

1919
import subprocess
20+
import re
2021

2122
def getClipboardData():
2223
p = subprocess.Popen(["pbpaste"], stdout=subprocess.PIPE)
@@ -30,6 +31,7 @@ def setClipboardData(data):
3031
p.stdin.close()
3132

3233
clipboard = str(getClipboardData())
33-
result = clipboard.lower().replace(" ", "_").replace("-", "_")
34+
result = re.sub(r"([a-z])([A-Z])", r"\1_\2", clipboard)
35+
result = result.lower().replace(" ", "_").replace("-", "_")
3436
setClipboardData(result)
3537
print(result)

0 commit comments

Comments
 (0)