As a workaround, I can use this shebang hack:
$ cat hello.psql
--() { :; }; exec psql -f "$0"
SELECT 'Hello World!';
$ ./hello.psql
?column?
--------------
Hello World!
(1 row)
$ psql -f hello.psql
?column?
--------------
Hello World!
(1 row)
But I would prefer to use a traditional (#!/usr/bin/env psql -f) shebang. It took a few hours on irc to hack this one together.