Provide environment overrides for psql file locations.
authorAndrew Dunstan
Sat, 3 Mar 2012 21:39:26 +0000 (16:39 -0500)
committerAndrew Dunstan
Sat, 3 Mar 2012 21:39:26 +0000 (16:39 -0500)
PSQL_HISTORY provides an alternative for the command history file,
and PSQLRC provides an alternative location for the .psqlrc file.

doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/input.c
src/bin/psql/startup.c

index 55aa5f2ac1dc7cde2d994c14733b147977af28f1..fdeaea604047c4053663ec529e03a8f195b79c39 100644 (file)
@@ -3340,6 +3340,26 @@ PSQL_EDITOR_LINENUMBER_ARG='--line '
     
    
 
+   
+    PSQL_HISTORY
+
+    
+     
+      Alternative location for the command history file. Tilde ("~") expansion is performed.
+     
+    
+   
+
+   
+    PSQLRC
+
+    
+     
+      Alternative location of the user's .psqlrc file. Tilde ("~") expansion is performed.
+     
+    
+   
+
    
     SHELL
 
@@ -3390,6 +3410,11 @@ PSQL_EDITOR_LINENUMBER_ARG='--line '
      to set up the client or the server to taste (using the \set
       and SET commands).
     
+    
+     The location of the user's ~/.psqlrc file can
+     also be set explicitly via the PSQLRC environment
+     setting.
+    
    
 
    
@@ -3411,6 +3436,11 @@ PSQL_EDITOR_LINENUMBER_ARG='--line '
      ~/.psql_history, or
      %APPDATA%\postgresql\psql_history on Windows.
     
+    
+     The location of the history file can
+     also be set explicitly via the PSQL_HISTORY environment
+     setting.
+    
    
   
  
index d77a731c2ec46b14814bf7edaf27cbe5d6057ee9..880e7e6511d7d47e3bfbd3992265412656aa1003 100644 (file)
@@ -285,6 +285,15 @@ initializeInput(int flags)
        history_lines_added = 0;
 
        histfile = GetVariable(pset.vars, "HISTFILE");
+
+       if (histfile == NULL)
+       {
+           char * envhist;
+           envhist = getenv("PSQL_HISTORY");
+           if (envhist != NULL && strlen(envhist) > 0)
+               histfile = envhist;
+       }
+
        if (histfile == NULL)
        {
            if (get_home_path(home))
index 166c227d6b6a8fef2ac002541b02b4ca6d866b8e..b5664dfd1d375b04676f02e95b827cfbf85880ec 100644 (file)
@@ -591,6 +591,7 @@ process_psqlrc(char *argv0)
    char        rc_file[MAXPGPATH];
    char        my_exec_path[MAXPGPATH];
    char        etc_path[MAXPGPATH];
+   char       *envrc;
 
    find_my_exec(argv0, my_exec_path);
    get_etc_path(my_exec_path, etc_path);
@@ -598,7 +599,14 @@ process_psqlrc(char *argv0)
    snprintf(rc_file, MAXPGPATH, "%s/%s", etc_path, SYSPSQLRC);
    process_psqlrc_file(rc_file);
 
-   if (get_home_path(home))
+   envrc = getenv("PSQLRC");
+   
+   if (envrc != NULL && strlen(envrc) > 0)
+   {
+       expand_tilde(&envrc);
+       process_psqlrc_file(envrc);
+   }
+   else if (get_home_path(home))
    {
        snprintf(rc_file, MAXPGPATH, "%s/%s", home, PSQLRC);
        process_psqlrc_file(rc_file);