Can textmate sort my code into readable columns?

I like to indent repetitive lines of code so they are easy to look at and see small differences. As an example, this is hard to read:

address = "1800 Washington St."
name = "George McGoo"
user_type = "admin"

but this is easy to read:

address = "1800 Washington St."
name = "George McGoo"
user_type = "admin"

Is there a way to do this in Textmate without wearing out my space bar?

1 Answer

I don't know anything about textmate, but you can solve the issue at hand with the command-line:

$ cat addresslist
address = "1800 Washington St."
name = "George McGoo"
user_type = "admin"
address = "1800 Washington St."
name = "George McGoo"
user_type = "admin"
$ awk -F'=' '{a[NR]=$0;l=length($1);if(l>max){max=l};last=NR}END{for(i=1;i<=last;i++){if(a[i]~/=/){c=a[i];gsub(/^[^=]+*=/,"",c);b=a[i];gsub(/=.*$/,"",b);printf "%-*s = %s\n",max,b,c}else{print a[i]}}}' addresslist
address = "1800 Washington St."
name = "George McGoo"
user_type = "admin"
address = "1800 Washington St."
name = "George McGoo"
user_type = "admin"

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like