zsh历史记录太短

问题描述 投票:32回答:2

[当我在Bash中运行history时,得到的结果很多(1000+)。但是,当我运行history zsh shell时,我只会得到15个结果。这使得zsh中的grepping历史几乎没有用。我的.zshrc文件包含以下几行:

HISTFILE=~/.zhistory
HISTSIZE=SAVEHIST=10000
setopt sharehistory
setopt extendedhistory

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


更新

[如果在zsh中调用history 1,我将获得所有历史记录,就像在Bash中使用history一样。我可以对该命令进行别名以获得相同的结果,但是我想知道为什么history在zsh和Bash中的行为不同。

zsh history
2个回答
47
投票

NVaughan(OP)已经在问题的更新中给出了答案:[historybash中的行为与在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不支持列出from条目号;您可以使用fc -l <n>,但是特定条目<n>必须存在,否则命令失败-参见下文。 )

  • 可选背景信息:

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

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


    9
    投票
    #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   
    

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

    © www.soinside.com 2019 - 2024. All rights reserved.