postgresql

Monday, August 31, 2009

cool psql prompts

I developed this as my standard prompt a few years back (double-click to see better):




- - - - - - - - - -

Here is the code to put in a .psqlrc file which should be created in your HOME directory:


--%M = database server
--%/ = database name
--%n = database user
--%> = port number
\echo '\n\033[33;1m-> Prompt is DBServer(LocalHost).DBName.DBServer.PortNumber [Local OS Timestamp]\033[0m\n'
\set PROMPT1 '\033[33;1m%M(from '`hostname`').%/.%n.%> [%`date`]\033[0m\n> '
\set PROMPT2 '> '


- - - - - - - - - -


You can change the colors by changing the [33 string to another number in the ASCII foreground list:
  • black 30
  • red 31
  • green 32
  • yellow 33
  • blue 34
  • magenta 35
  • cyan 36
  • white 37

- - - - - - - - - -


If you have scripts that call psql and you don't want this extra text showing up in the output, just add the -X option to the psql call to not use a .psqlrc file.

No comments:

Post a Comment