Last active
November 13, 2017 01:51
-
-
Save symmetriq/ece1b458be16dbbef989 to your computer and use it in GitHub Desktop.
BBEdit: Toggle Quotes
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 Quotes | |
#------------------------------------------------------------------------------- | |
# Jason Sims <[email protected]> | |
#------------------------------------------------------------------------------- | |
# | |
# Toggle between single and double quotes. Within the selected text, every | |
# double quote will become a single quote and vice-versa. | |
# | |
#------------------------------------------------------------------------------- | |
# | |
# 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 Quotes" in: | |
# BBEdit → Preferences → Menus & Shortcuts → Text → Apply Text Filter | |
# | |
#------------------------------------------------------------------------------- | |
# More scripts & snippets here: | |
# https://gist.github.com/symmetriq | |
#------------------------------------------------------------------------------- | |
# 1. Bookend with spaces (in case we have a trailing quote) | |
# 2. Split by `"` | |
# 3. Change `' to `"` | |
# 4. Join by `'` | |
# 5. Remove whitespace bookends | |
print " #{ARGF.set_encoding('UTF-8').read} ".split('"').map {|str| str.gsub(/'/, '"') }.join("'")[1...-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment