Skip to content

Instantly share code, notes, and snippets.

@symmetriq
Last active November 13, 2017 01:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save symmetriq/ece1b458be16dbbef989 to your computer and use it in GitHub Desktop.
Save symmetriq/ece1b458be16dbbef989 to your computer and use it in GitHub Desktop.
BBEdit: Toggle Quotes
#!/usr/bin/env ruby
#-------------------------------------------------------------------------------
# Toggle Quotes
#-------------------------------------------------------------------------------
# Jason Sims <jason@symmetriq.com>
#-------------------------------------------------------------------------------
#
# 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