Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Disabling history saves in init scripts



Here is a patch which disables history saving from the init scripts.  Explicit
saves with fc are not disabled.

On startup zsh runs all of the init scripts then it examines if the HISTFILE
parameter is set.  If it is set it loads the history from the file it points
to.  This means that we should not save history while executing the init
scripts since we may wipe out the existing history if the HISTFILE parameter
is set.

Cheers,

  Zoltan

*** 1.16	1995/11/05 19:31:55
--- Src/builtin.c	1995/11/06 00:06:18
***************
*** 4464,4470 ****
  	}
      }
      if (unset(NORCS) && interact) {
! 	savehistfile(getsparam("HISTFILE"), 1, isset(APPENDHISTORY) ? 3 : 0);
  	if (islogin && !subsh) {
  	    sourcehome(".zlogout");
  #ifdef GLOBAL_ZLOGOUT
--- 4464,4471 ----
  	}
      }
      if (unset(NORCS) && interact) {
! 	if (!nohistsave)
! 	    savehistfile(getsparam("HISTFILE"), 1, isset(APPENDHISTORY) ? 3 : 0);
  	if (islogin && !subsh) {
  	    sourcehome(".zlogout");
  #ifdef GLOBAL_ZLOGOUT
*** 1.9	1995/11/05 19:41:48
--- Src/exec.c	1995/11/06 00:08:29
***************
*** 1519,1525 ****
  
  	    if (cmd->flags & (CFLAG_EXEC|CFLAG_FAKE_EXEC)) {
  		/* only save the history file on a real exec */
! 		if ((cmd->flags & CFLAG_EXEC) && unset(NORCS) && interact)
  		    savehistfile(getsparam("HISTFILE"), 1, isset(APPENDHISTORY) ? 3 : 0);
  		exit(lastval);
  	    }
--- 1519,1525 ----
  
  	    if (cmd->flags & (CFLAG_EXEC|CFLAG_FAKE_EXEC)) {
  		/* only save the history file on a real exec */
! 		if ((cmd->flags & CFLAG_EXEC) && unset(NORCS) && interact && !nohistsave)
  		    savehistfile(getsparam("HISTFILE"), 1, isset(APPENDHISTORY) ? 3 : 0);
  		exit(lastval);
  	    }
***************
*** 1531,1537 ****
  	    /* only save the history file on a real exec */
  	    if (cmd->flags & CFLAG_EXEC) {
  		setiparam("SHLVL", --shlvl);
! 		if (unset(NORCS) && interact)
  		    /* save the history file through execs */
  		    savehistfile(getsparam("HISTFILE"), 1, isset(APPENDHISTORY) ? 3 : 0);
  	    }
--- 1531,1537 ----
  	    /* only save the history file on a real exec */
  	    if (cmd->flags & CFLAG_EXEC) {
  		setiparam("SHLVL", --shlvl);
! 		if (unset(NORCS) && interact && !nohistsave)
  		    /* save the history file through execs */
  		    savehistfile(getsparam("HISTFILE"), 1, isset(APPENDHISTORY) ? 3 : 0);
  	    }
*** 1.9	1995/11/05 19:59:57
--- Src/globals.h	1995/11/05 19:59:58
***************
*** 98,103 ****
--- 98,107 ----
   * trapping of SIGZERR, SIGEXIT. */
  
  EXTERN int noerrexit;
+ 
+ /* do not save history on exec and exit */
+ 
+ EXTERN int nohistsave;
   
  /* error/break flag */
   
*** 1.9	1995/11/05 20:02:20
--- Src/init.c	1995/11/06 00:05:21
***************
*** 688,693 ****
--- 688,694 ----
      locallevel = sourcelevel = 0;
      trapreturn = 0;
      noerrexit = 0;
+     nohistsave = 1;
      dirstack = newlinklist();
      bufstack = newlinklist();
      hsubl = hsubr = NULL;
***************
*** 796,801 ****
--- 797,803 ----
  	}
      }
      noerrexit = 0;
+     nohistsave = 0;
  }
  
  /* Miscellaneous initializations that happen after init scripts are run */



Messages sorted by: Reverse Date, Date, Thread, Author