Обсуждение: psql: present working directory

Поиск
Список
Период
Сортировка

psql: present working directory

От
"Brendan Jurd"
Дата:
Dear hackers,

Is there any interest in having a backslash command to psql that
prints the current working directory?  This would nicely complement
the functionality offered by \cd.

The command could be either a new command like \pwd, or simply make
this the behaviour of \cd with no argument; much the same way that \f
shows the current field separator when invoked without an argument.

Example:

postgres=> \cd /foo/bar/baz
postgres=> \cd
Working directory is "/foo/bar/baz".

Clearly it's a minor convenience feature, but I know I would use it,
and I don't see a downside.  Currently \cd with no argument does
nothing at all.

Happy to provide a patch in the absence of any objections.

Regards,
BJ


Re: psql: present working directory

От
Tom Lane
Дата:
"Brendan Jurd" <direvus@gmail.com> writes:
> Is there any interest in having a backslash command to psql that
> prints the current working directory?

You mean like "\!pwd" ?
        regards, tom lane


Re: psql: present working directory

От
Jerry Sievers
Дата:
"Brendan Jurd" <direvus@gmail.com> writes:

> Dear hackers,
> 
> Is there any interest in having a backslash command to psql that
> prints the current working directory?  This would nicely complement
> the functionality offered by \cd.

We have this through subshell invocation

\!pwd

HTH

> The command could be either a new command like \pwd, or simply make
> this the behaviour of \cd with no argument; much the same way that \f
> shows the current field separator when invoked without an argument.
> 
> Example:
> 
> postgres=> \cd /foo/bar/baz
> postgres=> \cd
> Working directory is "/foo/bar/baz".
> 
> Clearly it's a minor convenience feature, but I know I would use it,
> and I don't see a downside.  Currently \cd with no argument does
> nothing at all.
> 
> Happy to provide a patch in the absence of any objections.
> 
> Regards,
> BJ
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
> 
>                 http://www.postgresql.org/about/donate
> 

-- 
-------------------------------------------------------------------------------
Jerry Sievers   305 854-3001 (home)     Production Database Administrator               305 321-1144 (mobil    WWW
E-CommerceConsultant
 


Re: psql: present working directory

От
"Brendan Jurd"
Дата:
On 20 Nov 2006 08:24:48 -0500, Jerry Sievers <jerry@jerrysievers.com> wrote:
> "Brendan Jurd" <direvus@gmail.com> writes:
> > Is there any interest in having a backslash command to psql that
> > prints the current working directory?  This would nicely complement
> > the functionality offered by \cd.
>
> We have this through subshell invocation
>
> \!pwd
>
> HTH

Yep, that does the trick, and it is convenient.

I had a look at what \cd currently does if you give it no arguments.
I expected it to do nothing at all (since there is no output), but see
src/bin/psql/command.c lines 266 - 285.  Under win32 the working
directory is set to "/", on other systems it is set to the value of
the current user's home directory.

The intent seems to be to mimic the behaviour of "cd" at the shell.
Under Linux (at least), "cd" with no arguments at the shell does
indeed change to your home directory.  Personally I think printing out
the current directory would make more sense in the psql context, but
mimicking the shell certainly has value.

Maybe psql should print a line saying "Current directory was set to
'/home/you'." in this case?

Comments in the code point out that "cd" without arguments under
Windows normally prints out the current directory, so the chdir to "/"
isn't ideal, and would probably be trivial to change to mimic the
Windows command line behaviour.


Re: psql: present working directory

От
"Gurjeet Singh"
Дата:
On 20 Nov 2006 08:24:48 -0500, Jerry Sievers <jerry@jerrysievers.com> wrote:
We have this through subshell invocation

\!pwd

HTH

For the same effect on Windows (under cmd.exe), you need to do this:

\!cd

--
gurjeet[.singh]@EnterpriseDB.com
singh.gurjeet@{ gmail | hotmail | yahoo }.com