Index: doc/src/sgml/ref/psql-ref.sgml =================================================================== RCS file: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v retrieving revision 1.139 diff -c -c -r1.139 psql-ref.sgml *** doc/src/sgml/ref/psql-ref.sgml 9 Jun 2005 15:27:26 -0000 1.139 --- doc/src/sgml/ref/psql-ref.sgml 10 Jun 2005 15:33:22 -0000 *************** *** 1988,1993 **** --- 1988,2015 ---- + HISTFILE + + + This variable contains the filename used to save the history. + Its default value is ~/.psql_history. + For example, use: + + \set HISTFILE ~/.psql_history-:DBNAME + + in your ~/.psqlrc will get psql to + maintain a separate history for each database. + + + + This feature was shamelessly plagiarized from + Bash. + + + + + + HISTSIZE Index: src/bin/psql/input.c =================================================================== RCS file: /cvsroot/pgsql/src/bin/psql/input.c,v retrieving revision 1.43 diff -c -c -r1.43 input.c *** src/bin/psql/input.c 6 Jan 2005 18:29:09 -0000 1.43 --- src/bin/psql/input.c 10 Jun 2005 15:33:23 -0000 *************** *** 24,29 **** --- 24,31 ---- #ifdef USE_READLINE static bool useReadline; static bool useHistory; + char *psql_history; + enum histcontrol { *************** *** 177,192 **** if (GetVariable(pset.vars, "HISTSIZE") == NULL) SetVariable(pset.vars, "HISTSIZE", "500"); using_history(); ! if (get_home_path(home)) { ! char *psql_history; ! psql_history = pg_malloc(strlen(home) + 1 + ! strlen(PSQLHISTORY) + 1); ! sprintf(psql_history, "%s/%s", home, PSQLHISTORY); read_history(psql_history); - free(psql_history); - } } #endif --- 179,202 ---- if (GetVariable(pset.vars, "HISTSIZE") == NULL) SetVariable(pset.vars, "HISTSIZE", "500"); using_history(); ! ! if (GetVariable(pset.vars, "HISTFILE") == NULL) ! { ! if (get_home_path(home)) ! { ! psql_history = pg_malloc(strlen(home) + 1 + ! strlen(PSQLHISTORY) + 1); ! snprintf(psql_history, MAXPGPATH, "%s/%s", home, PSQLHISTORY); ! } ! } ! else { ! psql_history = pg_strdup(GetVariable(pset.vars, "HISTFILE")); ! expand_tilde(&psql_history); ! } ! if (psql_history) read_history(psql_history); } #endif *************** *** 227,251 **** #endif { #ifdef USE_READLINE ! if (useHistory) { ! char home[MAXPGPATH]; ! if (get_home_path(home)) ! { ! char *psql_history; ! int hist_size; ! ! hist_size = GetVariableNum(pset.vars, "HISTSIZE", -1, -1, true); ! if (hist_size >= 0) ! stifle_history(hist_size); ! ! psql_history = pg_malloc(strlen(home) + 1 + ! strlen(PSQLHISTORY) + 1); ! sprintf(psql_history, "%s/%s", home, PSQLHISTORY); ! write_history(psql_history); ! free(psql_history); ! } } #endif } --- 237,253 ---- #endif { #ifdef USE_READLINE ! if (useHistory && psql_history) { ! int hist_size; ! hist_size = GetVariableNum(pset.vars, "HISTSIZE", -1, -1, true); ! if (hist_size >= 0) ! stifle_history(hist_size); ! ! saveHistory(psql_history); ! free(psql_history); ! psql_history = NULL; } #endif }