Created
November 13, 2017 01:48
-
-
Save symmetriq/10aa4cfa2b2bf714070e721737b2e5ef to your computer and use it in GitHub Desktop.
BBEdit: Toggle CamelCase -
This file contains hidden or 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
#!/usr/bin/env ruby | |
#------------------------------------------------------------------------------- | |
# Toggle Camelcase - | |
#------------------------------------------------------------------------------- | |
# Jason Sims <[email protected]> | |
#------------------------------------------------------------------------------- | |
# | |
# Toggles between camelcase and hyphens | |
# e.g. doTheThing <-> do-the-thing | |
# | |
#------------------------------------------------------------------------------- | |
# | |
# Installation in BBEdit: | |
# | |
# 1. Place this file in your "Text Filters" directory: | |
# ~/Library/Application Support/BBEdit/Text Filters/ | |
# or | |
# ~/Dropbox/Application Support/BBEdit/Text Filters/ | |
# | |
# 2. Assign a keyboard shortcut to "Toggle CamelCase -" in: | |
# BBEdit → Preferences → Menus & Shortcuts → Text → Apply Text Filter | |
# | |
#------------------------------------------------------------------------------- | |
# More scripts & snippets here: | |
# https://gist.github.com/symmetriq | |
#------------------------------------------------------------------------------- | |
input = ARGF.set_encoding('UTF-8').read | |
if input.include? '-' | |
# has hyphens; convert to camelCase | |
print input.gsub(/_[A-Za-z]/) {|char| char[1].upcase } | |
else | |
# treat as camelCase (nothing will happen if the string contains no capital letters) | |
print input.gsub(/([A-Z])/, '-\1').downcase | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment