Last active
November 13, 2017 01:47
-
-
Save symmetriq/4315f9619f428f761d35 to your computer and use it in GitHub Desktop.
BBEdit: Toggle CamelCase _
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
#!/usr/bin/env ruby | |
#------------------------------------------------------------------------------- | |
# Toggle Camelcase _ | |
#------------------------------------------------------------------------------- | |
# Jason Sims <[email protected]> | |
#------------------------------------------------------------------------------- | |
# | |
# Toggles between camelcase and underscores | |
# 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 underscores; 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