Truncating strings with bash

This is particularly handy if you’re building up a comma separated list through concatenation and need to remove the final comma. The following snippet removes the final character from $test.

test="Hello world"
echo ${test:0:`expr length "$test" - 1`}

(Cribbed from the Advanced Bash-Scripting Guide.)

Switch off underlining for hyperlinks in OpenOffice

Our current document pipeline goes from Markdown (for content) through HTML (for structural transformations) to OpenOffice (for pagination etc.)

This is dandy but by default OpenOffice underlines hyperlinks and anything that looks like it could be converted into one (email addresses, URLs). It also colours them blue.

This is extremely annoying a problem, as our “structural transformations” include indexing, TOC, footnotes and other processes that produce useful hyperlinks that absolutely should not be underlined. Or blue.

Unless of course you want that Particle Physics Lab circa ’95 feel for your document.

Here’s the slightly non-obvious way to fix it.

  1. Bring up the styles and formatting dialog using Format > Styles and Formatting
  2. Choose the Character Styles section (second button from the left)
  3. Right click on Internet Link and choose Modify
  4. Go to the Font Effects tab
  5. Switch Underlining to (Without) and Font colour to Automatic

Relocating git-svn checkouts

I use git-svn to maintain backups of our entire SVN repository. It’s fast, secure and easy; and the git clone of the whole repository history, branches and all uses about the same space as a subversion needs for a single revision, single branch checkout. No brainer.

Originally we used svn+ssh:// to provide remote SVN access. But as we’ve begun to collaborate with more and more people, we’ve needed to open up subtrees of our repository. And rather than creating user accounts for all these folk we’ve been giving them https:// access. This means that www-data needs to own the repository, so everyone needs to switch over to the new access scheme.

For regular svn checkouts that’s easy enough:

OLD_URL = `svn info; grep URL; cut -d" " -f2`
svn switch --relocate $OLD_URL $NEW_URL

Unfortunately git-svn has no equivalent sub command. Fear not. You could just clone from the new repository location, but that would be horribly wasteful. The following procedure (mainly cribbed from GitWiki) will see you right:

  1. Using svn checkout HEAD from the https:// repository. Cache your authentication credentials so git-svn can use them if necessary. This is important.
  2. If there haven’t been any commits since your last git-svn rebase make one now e.g. touch kick; svn add kick; svn commit -m "Kicking git-svn". This is important.
  3. Now, in your git-svn checkout edit .git/config. In the svn section, comment out the old url entry (hash or semicolon are valid) and add a new one.
  4. git-svn fetch to fetch a new revision from the new repository
  5. In .git/config comment out the new url entry and restore the old one.
  6. git-svn rebase -l to perform a local rebase
  7. In .git/config comment out the old url entry and restore the new one.
  8. Enjoy the fresh minty taste.

Eclipse crashing in 64-bit Ubuntu?

There are, it seems, crashers in recent Ubuntu 8.10 amd64 sun-java6-jre packages. Eclipse seems especially adept at finding them. Here’s the fix that worked for us. Add the following to your $ECLIPSE_INSTALL/eclipse.ini:


And some background:

Must be connected to a terminal

Trying to connect to a remote detached screen over SSH? Receiving the Must be connected to a terminal error? If you’ve set your .profile to exec screen -R (as I had) and you’ve got multiple detached sessions (as I had) then you might well be worrying that you’ve locked yourself out (as I was).

Don’t worry.

ssh -t user@host screen -RR

But you might want to fix that .profile