Skip to content

Commit

Permalink
init: Make shell history unlimited (#1026)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cwhite911 committed Nov 17, 2020
1 parent 3d418ef commit 47e52ec
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/init/grass.py
Expand Up @@ -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"))

Expand Down Expand Up @@ -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"
Expand All @@ -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" ?
Expand All @@ -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:
Expand Down

0 comments on commit 47e52ec

Please sign in to comment.