Patch (tiny): \cd (change dir) for psql.

Started by Mark Hambyabout 25 years ago7 messagesgeneral
Jump to latest
#1Mark Hamby
mark@archer.leavenworth.army.mil

Here's a patch for a \cd (change dir) command in psql program.
It's very small and only adds a few lines.
Personally, I am surprised psql does not have this command.
It is EXTREMELY useful when \include'ing SQL scripts to set
up a database schema.

Hope you like,

Mark Hamby

P.S. I am not on the 'psql-patches' list, so responses should
be sent directly to me for more info or questions.

Attachments:

cd-patch.difapplication/octet-stream; name=cd-patch.difDownload+19-0
#2Lee Harr
missive@frontiernet.net
In reply to: Mark Hamby (#1)
Re: Patch (tiny): \cd (change dir) for psql.

On Mon, 26 Mar 2001 15:07:37 +0000 (UTC), Mark Hamby
<mark@archer.leavenworth.army.mil> wrote:

Here's a patch for a \cd (change dir) command in psql program.
It's very small and only adds a few lines.
Personally, I am surprised psql does not have this command.
It is EXTREMELY useful when \include'ing SQL scripts to set
up a database schema.

It's a good idea. This is an itch I've needed scratched many times.

#3Bruce Momjian
bruce@momjian.us
In reply to: Lee Harr (#2)
Re: Re: Patch (tiny): \cd (change dir) for psql.

On Mon, 26 Mar 2001 15:07:37 +0000 (UTC), Mark Hamby
<mark@archer.leavenworth.army.mil> wrote:

Here's a patch for a \cd (change dir) command in psql program.
It's very small and only adds a few lines.
Personally, I am surprised psql does not have this command.
It is EXTREMELY useful when \include'ing SQL scripts to set
up a database schema.

It's a good idea. This is an itch I've needed scratched many times.

Will be in 7.2.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#4will trillich
will@serensoft.com
In reply to: Bruce Momjian (#3)
Re: Re: Patch (tiny): \cd (change dir) for psql.

On Tue, Mar 27, 2001 at 09:52:05AM -0500, Bruce Momjian wrote:

On Mon, 26 Mar 2001 15:07:37 +0000 (UTC), Mark Hamby
<mark@archer.leavenworth.army.mil> wrote:

Here's a patch for a \cd (change dir) command in psql program.
It's very small and only adds a few lines.
Personally, I am surprised psql does not have this command.
It is EXTREMELY useful when \include'ing SQL scripts to set
up a database schema.

It's a good idea. This is an itch I've needed scratched many times.

Will be in 7.2.

and with it i'd imagine we'll also need

# return to previous directory, for the lazy
\cd -
# show current working directory
\cwd
\pwd

of course, we could continue working the way we are now:

somePsqlDb=> \q
% cd /some/where/over/the/rainbow
% psql mydata
mydata=>

but why? :)

--
It is always hazardous to ask "Why?" in science, but it is often
interesting to do so just the same.
-- Isaac Asimov, 'The Genetic Code'

will@serensoft.com
http://newbieDoc.sourceforge.net/ -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

#5Peter Eisentraut
peter_e@gmx.net
In reply to: will trillich (#4)
Re: Re: Patch (tiny): \cd (change dir) for psql.

will trillich writes:

and with it i'd imagine we'll also need

# return to previous directory, for the lazy
\cd -
# show current working directory
\cwd
\pwd

You can do this with

\!pwd

(Of course \!cd won't do what you want. This situation is similar to an
ftp client.)

--
Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/

#6Pruner Jan
pruner@cekia.cz
In reply to: Peter Eisentraut (#5)
RE: Re: Patch (tiny): \cd (change dir) for psql.

You can do this with

\!pwd

(Of course \!cd won't do what you want. This situation is
similar to an
ftp client.)

--
Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/

Why is not possible to run every bash command?
Something like '\ccd ..' for 'cd ..' or '\cpwd' for 'pwd' etc.
It's pretty simple.

Jan Pruner
jan@pruner.cz

#7will trillich
will@serensoft.com
In reply to: Pruner Jan (#6)
Re: Re: Patch (tiny): \cd (change dir) for psql.

On Thu, Mar 29, 2001 at 07:59:01AM +0200, Pruner Jan wrote:

You can do this with

\!pwd

(Of course \!cd won't do what you want. This situation is
similar to an
ftp client.)

--
Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/

Why is not possible to run every bash command?
Something like '\ccd ..' for 'cd ..' or '\cpwd' for 'pwd' etc.

well, the bang-notation is already there: \!ls \!grep \!find
\!who \!last \!pwd

It's pretty simple.

but it won't work for "cd" ... i know this one!

when a process forks (shield your eyes, everyone, give it some
privacy...) the 'child' inherits the same environment as the
'parent'. but after the fork, each is its own individual process
with its own environment. changing the directory of the parent
won't affect that of the child -- and VICE VERSA as well: namely,
spawning a child shell process, and then changing its default
working directory, will not matter one iota to the parent psql
process.

but you can fork off a quickie 'pwd' which will tell you what its
current directory is -- and given that there's no opportunity to
have it change its directory from the one it inherited from its
parent process, it'll match the 'pwd' of the parent 'psql'
process as well.

--
It is always hazardous to ask "Why?" in science, but it is often
interesting to do so just the same.
-- Isaac Asimov, 'The Genetic Code'

will@serensoft.com
http://newbieDoc.sourceforge.net/ -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!