Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Switch orientation of guillemets in Textmate from outwards to inwards (or vice-versa)
# user preferences for the builtin text bundle
PREF_FILE="$HOME/Library/Application Support/Avian/Bundles/Text.tmbundle/Preferences/Miscellaneous.tmPreferences"
# single and double guillemets in both directions
SINGLE_LEFT="<string>‹<\/string>"; SINGLE_RIGHT="<string>›<\/string>"
DOUBLE_LEFT="<string>«<\/string>"; DOUBLE_RIGHT="<string>»<\/string>"
# perl syntax used below
# -i: inplace editing
# -p: iterate over files
# -e: execute command
# -0: read file at once
# s/: substitute a string
# /s: multiline matching
# /g: substitute all occurences
# switch guillemets from outwards-facing («...») to inwards-facing (»...«)
perl -0pi -e "s/$SINGLE_LEFT(\s*)$SINGLE_RIGHT/$SINGLE_RIGHT\1$SINGLE_LEFT/sg" "$PREF_FILE"
perl -0pi -e "s/$DOUBLE_LEFT(\s*)$DOUBLE_RIGHT/$DOUBLE_RIGHT\1$DOUBLE_LEFT/sg" "$PREF_FILE"
# switch guillemets from inwards-facing (»...«) to outwards-facing («...»)
perl -0pi -e "s/$SINGLE_RIGHT(\s*)$SINGLE_LEFT/$SINGLE_LEFT\1$SINGLE_RIGHT/sg" "$PREF_FILE"
perl -0pi -e "s/$DOUBLE_RIGHT(\s*)$DOUBLE_LEFT/$DOUBLE_LEFT\1$DOUBLE_RIGHT/sg" "$PREF_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.