Explorar o código

init: Make shell history unlimited (#1026)

Updates Bash, Z shell, tcsh/csh history setting from 3000 which was applied only when unset to unlimited
which is applied always. What is unlimited or effectively unlimited differs for different shells.

Closes #969.
Corey White %!s(int64=4) %!d(string=hai) anos
pai
achega
47e52ec0d1
Modificáronse 1 ficheiros con 9 adicións e 5 borrados
  1. 9 5
      lib/init/grass.py

+ 9 - 5
lib/init/grass.py

@@ -1782,7 +1782,7 @@ def csh_startup(location, grass_env_file):
 
     f = open(cshrc, 'w')
     f.write("set home = %s\n" % userhome)
-    f.write("set history = 3000 savehist = 3000  noclobber ignoreeof\n")
+    f.write("set history = 10000000 savehist = (10000000 merge) noclobber ignoreeof\n")
     f.write("set histfile = %s\n" % os.path.join(os.getenv('HOME'),
                                                  ".history"))
 
@@ -1822,10 +1822,18 @@ def csh_startup(location, grass_env_file):
 def sh_like_startup(location, location_name, grass_env_file, sh):
     """Start Bash or Z shell (but not sh (Bourne Shell))"""
     if sh == 'bash':
+        # set bash history to record an unlimited command history
+        sh_history_limit = "-1" # unlimited
+        os.environ['HISTSIZE'] = sh_history_limit
+        os.environ['HISTFILESIZE'] = sh_history_limit
         sh_history = ".bash_history"
         shrc = ".bashrc"
         grass_shrc = ".grass.bashrc"
     elif sh == 'zsh':
+        # zsh does not have an unlimited history setting, so 1e8 is set as a proxy
+        sh_history_limit = "100000000" # proxy for unlimited
+        os.environ['SAVEHIST'] = sh_history_limit
+        os.environ['HISTSIZE'] = sh_history_limit
         sh_history = ".zsh_history"
         shrc = ".zshrc"
         grass_shrc = ".grass.zshrc"
@@ -1837,8 +1845,6 @@ def sh_like_startup(location, location_name, grass_env_file, sh):
     # bash histroy file handled in specific_addition
     if not sh == "bash":
         os.environ['HISTFILE'] = os.path.join(location, sh_history)
-    if not os.getenv('HISTSIZE') and not os.getenv('HISTFILESIZE'):
-        os.environ['HISTSIZE'] = "3000"
 
     # instead of changing $HOME, start bash with:
     #   --rcfile "$LOCATION/.bashrc" ?
@@ -1854,8 +1860,6 @@ def sh_like_startup(location, location_name, grass_env_file, sh):
     f = open(shell_rc_file, 'w')
 
     if sh == 'zsh':
-        if not os.getenv('SAVEHIST'):
-            os.environ['SAVEHIST'] = os.getenv('HISTSIZE')
         f.write('test -r {home}/.alias && source {home}/.alias\n'.format(
             home=userhome))
     else: