Lance Hankins got annoyed with having to eyeball ant’s output of the long classpaths and wrote a task to do the classpath output in a slightly more readable form.
Neat, but perhaps there is a more generic way to do it. After all, not only ant produces these long semi-column separated monstrosities.
So, I want to show how I do it with Vim (Why Vim…).
Let’s use Lance’s output as given.
- Copy and paste it into Vim.
- Notice that it is broken into multiple (23) lines. While he probably did it for a better web presentation, this also happens when somebody screen scrapes the classpath from the DOS window.
- Let’s combine all the lines back into one long one: :%j!.
This command means:
- in the command-line mode (:),
- for the whole buffer (%)
- join lines (j)
- without inserting or deleting any spaces on the join (!)
- Now, let’s split them on the semicolon: :s/;/^M/g.
In here, we are
- in the command mode again (:),
- working with the current line (no range indicated)
- doing a substitution (s/FROM/TO/)
- from semicolon (/;/)
- to a line break (^M, produced -at least on windows- with CTRL-Q CTRL-M key sequence),
- and repeating this substitution for the whole line (s/FROM/TO/g)
- Ok, we are done in less than 20 keystrokes including cut and paste and carriage returns!
- Let’s see what else we can do. How about sorting and deduping the entries? (after cleaning up the first line to remove the [echo….] bit)
- :%!sort -u. This will require Cygwin to be first on the path in the Windows environments.
- How about highlighting all the sprint jars in one color and all hibernate jars in another?
- :1OTF spring and :2OTF hibernate. This requires OTF Vim plugin.
- As an added benefit, the command above immediately highlight spring’s jar for hibernate as it is the only line with two colors on it. Could be useful to keep in mind.
I could go on for a while, but hopefully this will be a more useful and generic way to deal with long classpaths rather than having to write an ant task. KISS, DRY, etc.
BlogicBlogger Over and Out