You could simply place your scripts in your .psqlrc file:
\set uptime 'select now() - backend_start as uptime from pg_stat_activity where pid = pg_backend_pid();'
and then run the query in psql by prepending it with a colon :uptime
OR
if your scripts are long and you wish to better organize them then you could create your scripts directory ~/psqlrc.d or whatever and then (for example) (assuming a *nix OS):
echo "select now() - backend_start as uptime from pg_stat_activity where pid = pg_backend_pid();" > ~/psqlrc.d/uptime.sql
followed by editing your ~/.psqlrc file to add:
\set uptime '\\i ~/psqlrc.d/uptime.sql'
and once again invoke the script by typing :uptime in psql.