
Show HN: Pgcli – A CLI for Postgres with auto-completion and syntax highlighting - amjith
http://pgcli.com
======
amjith
I'm the author of pgcli.

There is an FAQ page: [http://pgcli.com/faq](http://pgcli.com/faq)

I'll be happy to answer questions here as well.

~~~
tgkokk
For the request on the homepage for a Homebrew formula:

From [1]:

> Homebrew generally won't accept libraries that can be installed correctly
> with `pip install foo`.

[1]:
[https://github.com/Homebrew/homebrew/blob/master/share/doc/h...](https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Python-
for-Formula-Authors.md)

~~~
amjith
Yes. But pgcli is not a python library, it's an application that happens to be
written in python.

> Homebrew is happy to accept applications that are built in Python, whether
> the apps are available from PyPI or not.

~~~
lloeki
Example: duplicity[0] is available via homebrew.

[0]:
[https://github.com/Homebrew/homebrew/blob/master/Library/For...](https://github.com/Homebrew/homebrew/blob/master/Library/Formula/duplicity.rb)

------
a3n
This looks really nice, especially the colors.

As a reminder/heads up, you can often get simple command line editing and
completion in tools like psql in a bash-like environment, just by having a
.inputrc file in your home directory. Basically anything that uses readline,
like bash, psql, ipython, etc.

Extra benefit, you don't need to set -o vi (or the other flavor) in your
.bashrc or on the command line; anything that uses readline (including bash
and many other cli interfaces) will read the .inputrc file and do what it
says. I'm often pleasantly surprised that a new cli tool uses my .inputrc.

[http://linux.die.net/man/3/readline](http://linux.die.net/man/3/readline)

[https://www.gnu.org/software/bash/manual/bashref.html#Comman...](https://www.gnu.org/software/bash/manual/bashref.html#Command-
Line-Editing)

You can easily add the capability to command line tools that you write. For
example:

[https://docs.python.org/2/library/readline.html](https://docs.python.org/2/library/readline.html)

~~~
euroclydon
> you can often get simple command line editing and completion in tools like
> psql in a bash-like environment, just by having a .inputrc file in your home
> directory.

I'm genuinely confused by this. Why do you need to .inputrc file? Doesn't
readline default to EMACS style command shortcuts? And isn't TAB the EMACS
(and near universal) key for auto-complete?

~~~
a3n
If you like the default behavior, then you don't need .inputrc.

If you want vi command line edit keybindings, then you do.

Or if you like emacs but you want to customize, then you need a .inputrc.

------
Svenstaro
Awesome! I made a package for Arch Linux and stuck it into AUR:
[https://aur.archlinux.org/packages/pgcli/](https://aur.archlinux.org/packages/pgcli/)

------
wldcordeiro
Awesome! Adding a django-extensions command for a 'dbshell_plus' that utilizes
this sounds like a great idea. I think I may just do that.

------
lobster_johnson
Looks great! Just reported an incompatibility with Unicode.

Also, is it possible to tweak the autocompletion so that hitting Enter selects
the first offered completion? Right now, you have to hit tab or use the arrow
keys to select.

A Homebrew formula would be great.

~~~
amjith
Thanks for the bug report. Sorry about the Unicode woes, I'll take a look.

Hitting enter to select the first completion is much harder. I can't promise
I'll be able to do this one.

A homebrew formula would be fantastic. I tried making it last night but I ran
into issues with psycopg2 dependency. So if you have any experience with
building brew formulae, I'd appreciate some help.

~~~
lobster_johnson
While I know how to do formulas, unfortunately I have no idea how to do it
cleanly with Python, which has its own package system.

------
rlvesco7
Does this work with emacs? I love the integration of psql and emacs, but this
would be even better.
[http://www.emacswiki.org/emacs/SqlMode](http://www.emacswiki.org/emacs/SqlMode)

~~~
bad_login
I have build [https://github.com/antoineB/emacs-
assistant](https://github.com/antoineB/emacs-assistant) to work with sql-mode
it provide a simple completion for table and columns.

For now it serve me well.

------
beefield
Based on 3 minute testing, I like, thanks.

If someone tries to install this on ubuntu with just the quick start
instructions and fails, note that you need to

sudo apt-get install libpq-dev

Obviously, this is told in the more detailed install instructions.

~~~
noir_lord
Also python-dev if you are installing on 14.04 Server (i.e. using Vagrant or
something).

------
RyanHamilton
I actually work on a piece of software for creating sql charts from the
command line ([http://www.sqldashboards.com/help/sqlchart-command-line-
sql-...](http://www.sqldashboards.com/help/sqlchart-command-line-sql-chart-
generator)),this is brilliant! Thanks.

------
asolove
Lazyweb: is there a way to get this to be the default handler for connecting
to my heroku db?

------
IbJacked
Looks pretty slick, I'll give it try when I get home.

I'll go ahead and ask, since I'm probably not the only one thinking it: will
there be a MySQL version? ;)

EDIT: oh, and I guess the name wouldn't be very fitting for a MySQL cli...

~~~
amjith
Copied from the FAQ page:

Probably. Now that I've worked out the hard parts (sqlcompletion and special
commands), I'd like to write a CLI for Sqlite and MySql. But I'm not sure if
I'll have the time to do it in the immediate future. But if you're interested
in doing it, I'd be happy to help you. Please get in touch.

------
xfalcox
Sorry, but how to see tables from other schemas besides public in the FROM
clause autocomplete?

~~~
amjith
I've created a GH issue for this.
[https://github.com/amjith/pgcli/issues/22](https://github.com/amjith/pgcli/issues/22)

Would you mind adding a bit of description to the issue, perhaps an example
sql statement?

------
pmontra
Tried it. It's wonderful. I think it will replace psql quickly, at least in my
workflow.

------
ravipratapm
This is cool! Thanks for sharing.

Considering I'm new to Postgres (been on MySQL for too many years), this is
definitely making my life easier because of the autocomplete :)

But a question for you: how does this help someone who's a power user of
Postgres?

------
pca2
This is great Is there support or planned support for expanded display? (\x in
psql)

~~~
amjith
Yes!

That is the most popular feature request so far.
[https://github.com/amjith/pgcli/issues/19](https://github.com/amjith/pgcli/issues/19)

------
klaussilveira
Does anyone know something similar, but for mysql?

------
tmaly
I wish there was something like this for Oracle. sqlplus is so painful

~~~
amjith
Did you try
[https://pypi.python.org/pypi/sqlpython](https://pypi.python.org/pypi/sqlpython)?

It's not quite the same as pgcli but I took some inspiration from that for
auto-completion.

------
random_number
Looks fantastic, great idea!

------
pca2
This is great Is there support or planned support for expanded display? (\x in
psql)

------
pca2
This is great Is there support or planned support for expanded display? (\x in
psql)

------
pca2
This is great Is there support or planned support for expanded display? (\x in
psql)

------
pca2
This is great Is there support or planned support for expanded display? (\x in
psql)

