Move, Rename, and Ne'er the Twain Shall Meet

Paul R. Brown @ 2007-12-12T20:27:05Z

The mv command in Unix has some subtlety to it in that it either moves or renames the file in question (never mind that it uses rename(2) to do it), but that subtlety is a good thing in that mv usually does what you expect it to do.

Not so with IntelliJ. I use IntelliJ for Java development, and while I do occasionally dally with Eclipse or Netbeans, I always come back. Anyway, with a bunch of packages to rearrange across a multi-module project, I tried using the "move" refactor, e.g., to change com.foo.x to com.foo.y. Contrary to my expectations, this produces com.foo.y.x, but not noticing immediately, I ended up with goofy package names like com.bar.impl.impl.impl. ((in classic Monty Python falsetto) That doesn't have much impl in it...) Grrrr.

A little commandline action will get things cleaned up in terms of file layout, e.g.:

find src -type file \
| sed -E '{h;G;s:\n: :;s/(impl\/)+/(impl\/)/;}' \
| xargs -n 2 mv

The first part of the sed program is a recipe for echoing the input as the first hunk of the line.

(comment bubbles) 0 comments

The "bad interpreter" Bad Error Message

Paul Brown @ 2006-11-26T14:44:00Z

Every so often, I try to run a shell script and get the otherwise unhelpful:

: bad interpreter: No such file or directory

It always takes me a few minutes to remember that this is from MS-DOS line endings, and this is the message that there's no interpreter named /bin/bash^M. The Emacs quickie to clean out the line endings is:

C-x [ENTER] f unix

From the commandline,

cat -v file

will show the ^M, and

cat filename | tr -d '\r' > newfile

will remove them.

(comment bubbles) 0 comments