zsh的历史太短了

NVa*_*han 19 history zsh

当我history在Bash中运行时,我得到了大量的结果(1000+).但是,当我运行historyzsh shell时,我只得到15个结果.这使得在zsh中的grepping历史大多无用.我的.zshrc文件包含以下行:

HISTFILE=~/.zhistory
HISTSIZE=SAVEHIST=10000
setopt sharehistory
setopt extendedhistory
Run Code Online (Sandbox Code Playgroud)

如何修复zsh以使我的shell历史记录更有用?


UPDATE

如果在zsh中我打电话给history 1我得到我的所有历史,就像我在Bash中一样history.我可以使用别名命令来获得相同的结果,但我想知道为什么history在zsh和Bash 中表现不同.

mkl*_*nt0 24

该任择议定书已经表示在更新的问题的答案:history在不同的行为bash比它在zsh:

简而言之:

  • zsh:
    • history仅列出最近15个历史记录条目
    • history 1列出所有 - 见下文.
  • bash:
    • history列出所有历史条目.

可悲的是,传递数字操作数history行为也不同:

  • zsh:
    • history <n>显示所有<n> - 开头的条目,因此history 1显示所有条目.
    • (history -<n>- 注意-- 显示<n>最近的条目,因此默认行为是有效的history -15)
  • bash:
    • history <n>显示<n>最近的条目.
    • (bash history不支持条目号列出;您可以使用fc -l <n>,但必须存在特定条目<n>,否则命令失败 - 请参阅下文.)

可选背景信息:

  • 在zsh中,history有效(实际上)是别名fc -l:seeman zshbuiltins
    • 有关许多与历史相关的功能,请参阅 man zshall
  • 在bash中,history是它自己的命令,其语法不同于fc -l
    • 看到: man bash
  • bash和zsh都支持fc -l <fromNum> [<toNum>]列出给定范围的历史条目:
    • bash:<fromNum>必须存在特定条目.
    • zsh:命令成功,只要至少1个条目属于(显式或隐含)范围.
    • 因此,fc -l 1在zsh中工作以返回所有历史条目,而在bash中它通常不会,因为条目#1通常不再存在(但是,如上所述,您可以使用history不带参数来列出bash中的所有条目).


小智 13

也许很晚了,但是看到这篇文章并尝试应用它,但失败了....所以实际上,将其放入.zshrc

alias history='history 1'
Run Code Online (Sandbox Code Playgroud)

在用完之前你会看到任何东西HIST_SIZE。查找我使用的命令(更改后.zshrc

history | grep "my_grep_string"
Run Code Online (Sandbox Code Playgroud)

  • 更改命令的含义总是有点不稳定......最好定义 `alias hist='history 1'` 这样原始 `history` 的含义就不会受到影响(如果有脚本)等使用它的人)。总的来说,我喜欢使用别名来让生活更轻松的想法。 (5认同)

Sea*_*ean 6

#set history size
export HISTSIZE=10000
#save history after logout
export SAVEHIST=10000
#history file
export HISTFILE=~/.zhistory
#append into history file
setopt INC_APPEND_HISTORY
#save only one command if 2 common are same and consistent
setopt HIST_IGNORE_DUPS
#add timestamp for each entry
setopt EXTENDED_HISTORY   
Run Code Online (Sandbox Code Playgroud)

这是我的设置,可以正常工作

  • +1对_useful settings_有用,但不能回答这个问题(zsh中的“ history”(不带参数)只显示了15个最新条目,因此是_display_问题)。 (3认同)