summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Rouhaud <julien.rouhaud@free.fr>2016-08-25 20:53:39 +0200
committerJulien Rouhaud <julien.rouhaud@free.fr>2016-08-25 21:08:11 +0200
commit3f310f5070d45852afda29ed50ba656ff1cb7465 (patch)
tree61550f5da28b289b171f66564357d513b7c3f104
parent02f86552f4c09078f8f5b219134dfbe477e75134 (diff)
Add more placeholders to prompt
-rwxr-xr-xpgcli/main.py3
-rw-r--r--pgcli/pgexecute.py10
2 files changed, 13 insertions, 0 deletions
diff --git a/pgcli/main.py b/pgcli/main.py
index 431e282f..4d29e0aa 100755
--- a/pgcli/main.py
+++ b/pgcli/main.py
@@ -682,6 +682,9 @@ class PGCli(object):
string = string.replace('\\u', self.pgexecute.user or '(none)')
string = string.replace('\\h', self.pgexecute.host or '(none)')
string = string.replace('\\d', self.pgexecute.dbname or '(none)')
+ string = string.replace('\\p', str(self.pgexecute.port) or '(none)')
+ string = string.replace('\\i', str(self.pgexecute.pid) or '(none)')
+ string = string.replace('\\#', "#" if (self.pgexecute.superuser) else ">")
string = string.replace('\\n', "\n")
return string
diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py
index 9552ce64..8538cd88 100644
--- a/pgcli/pgexecute.py
+++ b/pgcli/pgexecute.py
@@ -136,6 +136,9 @@ class PGExecute(object):
host = (host or self.host)
port = (port or self.port)
dsn = (dsn or self.dsn)
+ pid = -1
+ superuser = False
+ print("dsn: %s" % dsn)
if dsn:
if password:
dsn = "{0} password={1}".format(dsn, password)
@@ -154,6 +157,11 @@ class PGExecute(object):
password=unicode2utf8(password),
host=unicode2utf8(host),
port=unicode2utf8(port))
+
+ cursor = conn.cursor()
+
+ superuser = self._select_one(cursor, "select current_setting('is_superuser')::bool")[0]
+ pid = self._select_one(cursor, 'select pg_backend_pid()')[0]
conn.set_client_encoding('utf8')
if hasattr(self, 'conn'):
self.conn.close()
@@ -164,6 +172,8 @@ class PGExecute(object):
self.password = password
self.host = host
self.port = port
+ self.pid = pid
+ self.superuser = superuser
register_date_typecasters(conn)
register_json_typecasters(self.conn, self._json_typecaster)