Last active
August 29, 2015 14:03
-
-
Save rheinardkorf/6834dc067c7890b9f2c3 to your computer and use it in GitHub Desktop.
A simple ruby script to add to a TextMate bundle that aligns PHP key/value pairs.
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
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -wKU | |
# Author: Rheinard Korf | |
# Usage: | |
# * Create a new bundle (or add to existing bundle). | |
# * Create a new command (e.g. KeyValue Alignment) and set a shortcut key (e.g. Ctrl+Cmd+Option+] ) | |
# * Paste the code in the command editor and save the bundle (Cmd+S) | |
# | |
# Now select a set of key/value pairs (not the whole array) and try out the new command. | |
lines = ENV['TM_SELECTED_TEXT'].split("\n") | |
max_length = 0 | |
lines.each do | line | | |
temp = line.split(/\:|\=\>/) | |
if temp[0].length > max_length then max_length = temp[0].length end | |
end | |
lines.each do | line | | |
temp = line.split(/\:|\=\>/) | |
print temp[0].ljust(max_length) + '=>' | |
puts temp[1] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns this:
into this: