How to save database connection information when using `psql`?
Thanks to the comment from @a_horse_with_no_name:
Enter the details in ~/.pg_service.conf, for example:
#comment
[myconnection]
host=localhost
port=5432
user=myuser
dbname=mydb
password=mypassword

Then set a PGSERVICE environment variable specifying which connection to use
echo PGSERVICE=myconnection

Then simply entering psql should make the connection.