psqlrc.patch
application/octet-stream
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/bin/psql/help.c | 1 | 0 |
| src/bin/psql/startup.c | 23 | 7 |
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 6037351..0dd34ea 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -99,6 +99,7 @@ usage(void)
printf(_(" -v, --set=, --variable=NAME=VALUE\n"
" set psql variable NAME to VALUE\n"));
printf(_(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n"));
+ printf(_(" --psqlrc=FILENAME read startup commands from file (instead of ~/.psqlrc)\n"));
printf(_(" -1 (\"one\"), --single-transaction\n"
" execute command file as a single transaction\n"));
printf(_(" --help show this help, then exit\n"));
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 61c7f11..043da81 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -68,11 +68,12 @@ struct adhoc_opts
bool no_readline;
bool no_psqlrc;
bool single_txn;
+ char *psqlrc;
};
static void parse_psql_options(int argc, char *argv[],
struct adhoc_opts * options);
-static void process_psqlrc(char *argv0);
+static void process_psqlrc(char *argv0, struct adhoc_opts *options);
static void process_psqlrc_file(char *filename);
static void showVersion(void);
static void EstablishVariableSpace(void);
@@ -247,8 +248,7 @@ main(int argc, char *argv[])
*/
if (options.action == ACT_FILE)
{
- if (!options.no_psqlrc)
- process_psqlrc(argv[0]);
+ process_psqlrc(argv[0], &options);
successResult = process_file(options.action_string, options.single_txn);
}
@@ -291,8 +291,7 @@ main(int argc, char *argv[])
*/
else
{
- if (!options.no_psqlrc)
- process_psqlrc(argv[0]);
+ process_psqlrc(argv[0], &options);
connection_warnings(true);
if (!pset.quiet && !pset.notty)
@@ -355,6 +354,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
{"password", no_argument, NULL, 'W'},
{"expanded", no_argument, NULL, 'x'},
{"no-psqlrc", no_argument, NULL, 'X'},
+ {"psqlrc", required_argument, NULL, 1},
{"help", no_argument, NULL, '?'},
{NULL, 0, NULL, 0}
};
@@ -515,6 +515,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
case 'X':
options->no_psqlrc = true;
break;
+ case 1:
+ options->psqlrc = pg_strdup(optarg);
+ break;
case '1':
options->single_txn = true;
break;
@@ -563,12 +566,16 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
* Load .psqlrc file, if found.
*/
static void
-process_psqlrc(char *argv0)
+process_psqlrc(char *argv0, struct adhoc_opts *options)
{
char home[MAXPGPATH];
char rc_file[MAXPGPATH];
char my_exec_path[MAXPGPATH];
char etc_path[MAXPGPATH];
+ char *env_rc_file;
+
+ if (options->no_psqlrc)
+ return;
find_my_exec(argv0, my_exec_path);
get_etc_path(my_exec_path, etc_path);
@@ -576,7 +583,16 @@ process_psqlrc(char *argv0)
snprintf(rc_file, MAXPGPATH, "%s/%s", etc_path, SYSPSQLRC);
process_psqlrc_file(rc_file);
- if (get_home_path(home))
+ env_rc_file = getenv("PSQLRC");
+ if (options->psqlrc)
+ {
+ process_psqlrc_file(options->psqlrc);
+ }
+ else if (env_rc_file)
+ {
+ process_psqlrc_file(env_rc_file);
+ }
+ else if (get_home_path(home))
{
snprintf(rc_file, MAXPGPATH, "%s/%s", home, PSQLRC);
process_psqlrc_file(rc_file);