Last active
November 13, 2017 01:49
-
-
Save symmetriq/13c5a2e4699e34518dff to your computer and use it in GitHub Desktop.
BBEdit: Toggle Parentheses
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 Parentheses | |
#------------------------------------------------------------------------------- | |
# Jason Sims <[email protected]> | |
#------------------------------------------------------------------------------- | |
# | |
# For languages with optional parentheses, such as Ruby and CoffeeScript. | |
# | |
# Wraps a selection with parentheses if they're not already present. | |
# Removes parentheses and adds leading space if the selection starts and ends | |
# with parentheses. | |
# | |
#------------------------------------------------------------------------------- | |
# | |
# 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 Parentheses" 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[0] == '(' and input[-1] == ')' | |
# has parentheses; remove them (and add leading space) | |
print " #{input[1..-2]}" | |
else | |
# no parentheses; add them (and strip whitespace) | |
print "(#{input.strip})" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment