shi*_*ish 6 command-history zsh
我看到了选项 extended_history 并看到它在 zsh中的Per-directory history 中使用,但还没有真正理解 extended_history 实际上做了什么?
什么信息。将在 zsh_history 中可用,否则如果未设置此选项则不会。
从http://zsh.sourceforge.net/Doc/Release/Options.html#Options它说 -
EXTENDED_HISTORY <C>
Save each command’s beginning timestamp (in seconds since the epoch) and the duration (in seconds) to the history file. The format of this prefixed data is:
‘: <beginning time>:<elapsed seconds>;<command>’.
Run Code Online (Sandbox Code Playgroud)
但至少在运行历史命令时我看不到它有任何好处 -
shirish@debian ~ % history | grep tail -5
601* exit
602* history
603* exit
604 cd
605 cat ~/.zsh/.zshrc
606 tail -5 history
Run Code Online (Sandbox Code Playgroud)
这是我~/.zsh/.zshrc
的设置方式-
shirish@debian ~ % cat ~/.zsh/.zshrc
# Lines configured by zsh-newuser-install
HISTFILE=~/.zsh//.histfile
HISTSIZE=1000
SAVEHIST=100000
setopt inc_append_history autocd nomatch notify share_history extended_history
bindkey -e
# End of lines configured by zsh-newuser-install
# display how long all tasks over 10 seconds take
export REPORTTIME=10
# The following lines were added by compinstall
zstyle :compinstall filename '/home/shirish/.zsh//.zshrc'
autoload -Uz compinit promptinit
compinit
promptinit
# End of lines added by compinstall
prompt adam1
Run Code Online (Sandbox Code Playgroud)
设置选项后或将其取出后我都没有看到任何区别,没有任何有意义的区别。
shirish@debian ~ % cat ~/.zsh/.zshrc | grep setopt
setopt inc_append_history autocd nomatch notify share_history extended_history
shirish@debian ~ % source ~/.zsh/.zshrc
shirish@debian ~ % history -E
337 11.1.2018 23:33 history | grep apg
338 11.1.2018 23:33 man apg
339 11.1.2018 23:33 cd
340 11.1.2018 23:33 apg -a 1 -M n -n 3 -m 20
341 11.1.2018 23:33 apg -a 1 -M SNCL -n 3 -m 20
342 11.1.2018 23:33 history
343 11.1.2018 23:33 history -E
344 11.1.2018 23:33 leafpad ~/.zsh/.zshrc
345 11.1.2018 23:33 cat ~/.zsh/.zshrc
346 11.1.2018 23:33 source ~/.zsh/.zshrc
347 11.1.2018 23:33 history -E
348 11.1.2018 23:33 exit
349 11.1.2018 23:33 history -E
350 11.1.2018 23:34 leafpad ~/.zsh/.zshrc
351 11.1.2018 23:35 cat ~/.zsh/.zshrc | grep setopt
352 11.1.2018 23:35 source ~/.zsh/.zshrc
shirish@debian ~ % leafpad ~/.zsh/.zshrc
shirish@debian ~ % source ~/.zsh/.zshrc
shirish@debian ~ % history -E
340 11.1.2018 23:33 apg -a 1 -M n -n 3 -m 20
341 11.1.2018 23:33 apg -a 1 -M SNCL -n 3 -m 20
342 11.1.2018 23:33 history
343 11.1.2018 23:33 history -E
344 11.1.2018 23:33 leafpad ~/.zsh/.zshrc
345 11.1.2018 23:33 cat ~/.zsh/.zshrc
346 11.1.2018 23:33 source ~/.zsh/.zshrc
347 11.1.2018 23:33 history -E
348 11.1.2018 23:33 exit
349 11.1.2018 23:33 history -E
350 11.1.2018 23:34 leafpad ~/.zsh/.zshrc
351 11.1.2018 23:35 cat ~/.zsh/.zshrc | grep setopt
352 11.1.2018 23:35 source ~/.zsh/.zshrc
353 11.1.2018 23:35 history -E
354 11.1.2018 23:36 leafpad ~/.zsh/.zshrc
355 11.1.2018 23:36 source ~/.zsh/.zshrc
shirish@debian ~ % cat ~/.zsh/.zshrc | grep setopt
setopt inc_append_history autocd nomatch notify share_history
Run Code Online (Sandbox Code Playgroud)
可以看出,似乎没有任何区别。
% zsh --version
zsh 5.4.2 (x86_64-debian-linux-gnu)
Run Code Online (Sandbox Code Playgroud)
小智 6
无论选项如何,输出history -E
始终相同EXTENDED_HISTORY
。命令的持续时间直接存储在历史文件中(只需检查该文件即可查看值)。
然而,另一个问题是有一些选项可以覆盖此行为。您可以通过运行类似的命令来测试它是否正常工作sleep 3
,这应该会产生如下所示的条目:
pol@host ~ $ sleep 3
pol@host ~ $ tail -1 ${HISTFILE}
: 1530663493:3;sleep 3
pol@host ~ $ setopt | grep hist
extendedhistory
histignoredups
incappendhistorytime
Run Code Online (Sandbox Code Playgroud)
您可以看到“持续时间”值为 3。如果它不是 3,则很可能您设置了另一个阻止EXTENDED_HISTORY
工作的选项。这些包括SHARED_HISTORY
和INC_APPEND_HISTORY
。如果您需要前者,那么您就不走运了。对于后一种情况,INC_APPEND_HISTORY_TIME
如果您还想拥有EXTENDED_HISTORY
值(如我上面所述),则可以使用另一种替代方法。
归档时间: |
|
查看次数: |
3186 次 |
最近记录: |