The original code this was based on is pretty old now (originally written in 2012) and I think connection strings will let you pass in the password without the pgpass file hack I originally wrote back in the day.
psql "sslmode=require host=localhost dbname=test"
via