The Wayback Machine - https://web.archive.org/web/20200613153931/https://github.com/dbcli/pgcli/issues/963
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\H prompt variable shows /tmp for unix domain socket connection #963

Open
thorstenkampe opened this issue Nov 3, 2018 · 4 comments
Open

\H prompt variable shows /tmp for unix domain socket connection #963

thorstenkampe opened this issue Nov 3, 2018 · 4 comments
Labels

Comments

@thorstenkampe
Copy link

@thorstenkampe thorstenkampe commented Nov 3, 2018

pgcli shows /tmp for unix domain socket connections (prompt is \u@\H:\p/\d dbcli> ). psql shows [local] instead.

Port shows as 5432 while it probably should be "(none)" since domain sockets don't have ports. psql also shows 5432.

> psql postgresql://postgres:password@
psql (11.0)
Type "help" for help.

postgres@[local]:5432/postgres psql> \q

> pgcli postgresql://postgres:password@
Server: PostgreSQL 11.0
Version: 2.0.0
[...]
postgres@/tmp:5432/postgres dbcli>
@j-bennet
Copy link
Contributor

@j-bennet j-bennet commented Nov 3, 2018

Thank you for the bug report! /tmp is not a problem - I don't think we need to copy psql in everything. But yes, showing port in case of unix socket connection is a bit weird.

@j-bennet j-bennet added the easy label Nov 3, 2018
@thorstenkampe
Copy link
Author

@thorstenkampe thorstenkampe commented Nov 3, 2018

Well, /tmp is not a "problem" but also not what \H promises: "\H - Hostname of the server". The domain socket file is /tmp/.s.PGSQL.5432 - that's where it comes from.

In that regard, [local] is more informative, in my opinion.

@j-bennet
Copy link
Contributor

@j-bennet j-bennet commented Nov 3, 2018

Perhaps - I don't have a strong opinion on this one. :) In case you'd like to take a stab at fixing it, here is the relevant code:

pgcli/pgcli/main.py

Lines 888 to 903 in 589c2ab

def get_prompt(self, string):
# should be before replacing \\d
string = string.replace('\\dsn_alias', self.dsn_alias or '')
string = string.replace('\\t', self.now.strftime('%x %X'))
string = string.replace('\\u', self.pgexecute.user or '(none)')
host = self.pgexecute.host or '(none)'
string = string.replace('\\H', host)
short_host, _, _ = host.partition('.')
string = string.replace('\\h', short_host)
string = string.replace('\\d', self.pgexecute.dbname or '(none)')
string = string.replace('\\p', str(
self.pgexecute.port) if self.pgexecute.port is not None else '5432')
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

@thorstenkampe
Copy link
Author

@thorstenkampe thorstenkampe commented Nov 4, 2018

That should be it:

@@ -891,9 +891,13 @@
         string = string.replace('\\t', self.now.strftime('%x %X'))
         string = string.replace('\\u', self.pgexecute.user or '(none)')
         host = self.pgexecute.host or '(none)'
-        string = string.replace('\\H', host)
-        short_host, _, _ = host.partition('.')
-        string = string.replace('\\h', short_host)
+        if self.pgexecute.get_socket_directory() == host:
+            string = string.replace('\\H', '[local]')
+            string = string.replace('\\h', '[local]')
+        else:
+            string = string.replace('\\H', host)
+            short_host, _, _ = host.partition('.')
+            string = string.replace('\\h', short_host)
         string = string.replace('\\d', self.pgexecute.dbname or '(none)')
         string = string.replace('\\p', str(
             self.pgexecute.port) if self.pgexecute.port is not None else '5432')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.