Add \cd command to psql.
This commit is contained in:
parent
ab420e2114
commit
232724af0d
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.49 2001/05/06 17:38:31 petere Exp $
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.50 2001/05/07 19:31:33 petere Exp $
|
||||
Postgres documentation
|
||||
-->
|
||||
|
||||
@ -217,6 +217,23 @@ testdb=>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>\cd</literal> <optional><replaceable>directory</replaceable></optional></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Change the current working directory to
|
||||
<replaceable>directory</replaceable>. Without argument,
|
||||
change to the current user's home directory.
|
||||
</para>
|
||||
|
||||
<tip>
|
||||
<para>
|
||||
To print your current working directory, use <literal>\!pwd</literal>.
|
||||
</para>
|
||||
</tip>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>\C</literal> [ <replaceable class="parameter">title</replaceable> ]</term>
|
||||
<listitem>
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright 2000 by PostgreSQL Global Development Group
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.50 2001/05/06 21:15:51 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.51 2001/05/07 19:31:33 petere Exp $
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
#include "command.h"
|
||||
@ -11,6 +11,9 @@
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#ifdef HAVE_PWD_H
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
#include <sys/types.h> /* for umask() */
|
||||
#include <sys/stat.h> /* for stat() */
|
||||
@ -256,6 +259,45 @@ exec_command(const char *cmd,
|
||||
free(opt2);
|
||||
}
|
||||
|
||||
/* \cd */
|
||||
else if (strcmp(cmd, "cd") == 0)
|
||||
{
|
||||
char *opt = scan_option(&string, OT_NORMAL, NULL);
|
||||
char *dir;
|
||||
|
||||
if (opt)
|
||||
dir = opt;
|
||||
else
|
||||
{
|
||||
#ifndef WIN32
|
||||
struct passwd *pw;
|
||||
|
||||
pw = getpwuid(geteuid());
|
||||
if (!pw)
|
||||
{
|
||||
psql_error("could not get home directory: %s\n", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
dir = pw->pw_dir;
|
||||
#else /* WIN32 */
|
||||
/* On Windows, 'cd' without arguments prints the current
|
||||
directory, so if someone wants to code this here
|
||||
instead... */
|
||||
dir = "/";
|
||||
#endif /* WIN32 */
|
||||
}
|
||||
|
||||
if (chdir(dir) == -1)
|
||||
{
|
||||
psql_error("\\%s: could not change directory to '%s': %s\n",
|
||||
cmd, dir, strerror(errno));
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (opt)
|
||||
free(opt);
|
||||
}
|
||||
|
||||
/* \copy */
|
||||
else if (strcasecmp(cmd, "copy") == 0)
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright 2000 by PostgreSQL Global Development Group
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.37 2001/03/22 04:00:20 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.38 2001/05/07 19:31:33 petere Exp $
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
#include "help.h"
|
||||
@ -196,6 +196,7 @@ slashUsage(void)
|
||||
fprintf(fout, " \\c[onnect] [dbname|- [user]]\n"
|
||||
" connect to new database (currently '%s')\n", PQdb(pset.db));
|
||||
fprintf(fout, " \\C <title> table title\n");
|
||||
fprintf(fout, " \\cd [<dir>] change the current working directory\n");
|
||||
fprintf(fout, " \\copy ... perform SQL COPY with data stream to the client machine\n");
|
||||
fprintf(fout, " \\copyright show PostgreSQL usage and distribution terms\n");
|
||||
fprintf(fout, " \\d <table> describe table (or view, index, sequence)\n");
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright 2000 by PostgreSQL Global Development Group
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.30 2001/04/14 22:55:02 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.31 2001/05/07 19:31:33 petere Exp $
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
@ -725,12 +725,13 @@ psql_completion(char *text, int start, int end)
|
||||
|
||||
COMPLETE_WITH_LIST(my_list);
|
||||
}
|
||||
else if (strcmp(prev_wd, "\\e") == 0 || strcmp(prev_wd, "\\edit") == 0 ||
|
||||
else if (strcmp(prev_wd, "\\cd") == 0 ||
|
||||
strcmp(prev_wd, "\\e") == 0 || strcmp(prev_wd, "\\edit") == 0 ||
|
||||
strcmp(prev_wd, "\\g") == 0 ||
|
||||
strcmp(prev_wd, "\\i") == 0 || strcmp(prev_wd, "\\include") == 0 ||
|
||||
strcmp(prev_wd, "\\o") == 0 || strcmp(prev_wd, "\\out") == 0 ||
|
||||
strcmp(prev_wd, "\\o") == 0 || strcmp(prev_wd, "\\out") == 0 ||
|
||||
strcmp(prev_wd, "\\s") == 0 ||
|
||||
strcmp(prev_wd, "\\w") == 0 || strcmp(prev_wd, "\\write") == 0
|
||||
strcmp(prev_wd, "\\w") == 0 || strcmp(prev_wd, "\\write") == 0
|
||||
)
|
||||
matches = completion_matches(text, filename_completion_function);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user