Wednesday, April 13, 2011

Bash history, caret, search & replace

I've been a (blind) user of bash's "caret replacement" for ages, but have occasionally wondered how to replace all occurences of a word, rather than the first.

$ echo "foo bar baz foo"
foo bar baz foo
$ ^foo^quux
echo "quux bar baz foo"
quux bar baz foo

The answer is to use the more robust event designator syntax: !!:gs/search/replace/

$ echo "foo bar baz foo"
foo bar baz foo
$ !!:gs/foo/quux/
echo "quux bar baz quux"
quux bar baz quux

While on the topic of esoteric bash commands, here's another good one. You may (?) know of !$ which references the last argument of the last command in history. That's just an alias for !!:$, which shows the more general form of the command. You can access any argument of any command in history.

$ echo "test" > /tmp/blah.txt 
$ cat !!:3
cat /tmp/blah.txt
test

There's lots more. In particular, you can operate on any command in history, not just the last one (!!). See the bash manual link in the references below.

References

Thursday, April 7, 2011

Scala method signature rules

I came across a great post on the IDEA Scala Plugin message board the other day. Apparently there are best-practices/conventions for writing method signatures in Scala. Adhering to these rules communicates to the user more than just argument and return types: it can tell you if a method has side-effects, or is meant to be a "property".
Check it out: Rules for Scala method signatures.
Also check out IDEA 10: the best Scala IDE.