とりあえずawkで作ってみた(routes.rake)
task routes: :environment do
puts `bundle exec rails routes | awk '
BEGIN {
n = 0
}
$0 ~ /^[[:space:]]*Prefix[[:space:]]+/{
n += 1
lines[n] = $0
mrn = length($1)
match($0, /^[[:space:]]+/)
lc = RLENGTH
mpn = length("URI Pattern")
match($0, /URI Pattern/)
rc = RSTART + RLENGTH
next
}
$0 ~ /turbo\\/native|\\/action_mailbox\\/|\\/active_storage\\//{ next }
{
n += 1
lines[n] = $0
if (length($1) > mrn) {
mrn = length($1)
match($0, /^[[:space:]]+/)
lc = RLENGTH
}
if (length($3) > mpn) {
mpn = length($3)
regex = $3
gsub(/[\\/\\(\\)\\[\\]\\{\\}\\*\\?\\.\\+\\-\\"]/, "\\\\\\\\&", regex)
match($0, regex)
rc = RSTART + RLENGTH
}
}
END {
for (i = 1; i <= n; i++) {
left = substr(lines[i], 1, rc)
left = substr(left, lc + 1)
right = substr(lines[i], rc)
sub(/^[[:space:]]*/, "", right)
print left right
}
}'`
end
出力結果はこんなかんじ
kiri@smtp:~/projects/rails/sample_view[1855]% rake routes
Prefix Verb URI Pattern Controller#Action
books_show GET /books/show(.:format) books#show
books_index GET /books/index(.:format) books#index
kiri@smtp:~/projects/rails/sample_view[1856]%