Re: psql color hostname prompt

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: Cal Heldenbrand <cal(at)fbsdata(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: psql color hostname prompt
Date: 2016-04-25 14:33:30
Message-ID: CA+bJJbzg4qwGEUbFosCE05VA3wcVt9fCifZXip5BpabTg=Spiw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Cal:

On Mon, Apr 25, 2016 at 3:55 PM, Cal Heldenbrand <cal(at)fbsdata(dot)com> wrote:
> I whipped up a psqlrc and companion shell script to provide a colored prompt
> with the hostname of the machine you're connected to. It works for both
> local sockets and remote connections too.

Color may be nice, but as previously pointed it can distort things.

> /usr/local/pgsql/etc/psqlrc
> ==============================================
> -- PROMPT1 is the primary prompt
> \set PROMPT1
> '%[%033[1;31m%]%`/usr/local/pgsql/etc/psql_hostname.sh`%[%033[0m%]
> %n(at)%/%R%#%x '

And you are exec'ing in every round ( not too big, but I come from a
time of slow forks).

I think psql ( at least in 9.3 didn't bother looking behind ) gives you enough:

cdrs=> \set PROMPT1 %M:%>-%x-%:AUTOCOMMIT:-:PROMPT1
db1:5432--on:-cdrs=> begin;
BEGIN
db1:5432-*-on:-cdrs=> commit;
COMMIT
db1:5432--on:-cdrs=> \c apc -
psql (9.4.7, server 9.3.10)
You are now connected to database "apc" as user "folarte".
db1:5432--on:-apc=>

And you can color it:

db1:5432--on:-apc=> \set PROMPT1 '%[%033[1;31m%]%M%[%033[0m%]%n(at)%/%R%#%x '
<RED>db1</RED>folarte(at)apc=> -- not a fan of html mail.

lsof may give you longer or more acurate names, but I think std
escapes are enough.

Francisco Olarte.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2016-04-25 14:36:45 Re: psql color hostname prompt
Previous Message Bráulio Bhavamitra 2016-04-25 14:29:35 Re: Columnar store as default for PostgreSQL 10?