AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 691511
Accepted
Govind Rai
Govind Rai
Asked: 2022-02-21 16:29:12 +0800 CST2022-02-21 16:29:12 +0800 CST 2022-02-21 16:29:12 +0800 CST

zsh history 命令支持比文档状态更多的选项

  • 772

zsh 中的 history 命令支持类似的选项-c,-w即使文档声明没有这样的选项。

运行man zshbuiltins显示历史命令的文档。它说:

       history
              Same as fc -l.

滚动到fc同一 man 文件中较低的命令文档说:

       fc [ -e ename ] [ -LI ] [ -m match ] [ old=new ... ] [ first [ last ] ]
       fc -l [ -LI ] [ -nrdfEiD ] [ -t timefmt ] [ -m match ]
             [ old=new ... ] [ first [ last ] ]
       fc -p [ -a ] [ filename [ histsize [ savehistsize ] ] ]
       fc -P
       fc -ARWI [ filename ]
              The fc command controls the interactive history mechanism.  Note that reading and writing of history options is only performed if the shell is interactive.  Usually this is
              detected automatically, but it can be forced by setting the interactive option when starting the shell.

              The first two forms of this command select a range of events from first to last from the history list.  The arguments first and last may be specified as a number or as a string.
              A negative number is used as an offset to the current history event number.  A string specifies the most recent event beginning with the given string.  All substitutions old=new,
              if any, are then performed on the text of the events.

              In addition to the number range,
              -I     restricts to only internal events (not from $HISTFILE)
              -L     restricts to only local events (not from other shells, see SHARE_HISTORY in zshoptions(1) -- note that $HISTFILE is considered local when read at startup)
              -m     takes the first argument as a pattern (should be quoted) and only the history events matching this pattern are considered

              If first is not specified, it will be set to -1 (the most recent event), or to -16 if the -l flag is given.  If last is not specified, it will be set to first, or to -1 if the -l
              flag is given.  However, if the current event has added entries to the history with `print -s' or `fc -R', then the default last for -l includes all new history entries since the
              current event began.

              When the -l flag is given, the resulting events are listed on standard output.  Otherwise the editor program specified by -e ename is invoked on a file containing these history
              events.  If -e is not given, the value of the parameter FCEDIT is used; if that is not set the value of the parameter EDITOR is used; if that is not set a builtin default,
              usually `vi' is used.  If ename is `-', no editor is invoked.  When editing is complete, the edited command is executed.

              The flag -r reverses the order of the events and the flag -n suppresses event numbers when listing.

              Also when listing,
              -d     prints timestamps for each event
              -f     prints full time-date stamps in the US `MM/DD/YY hh:mm' format
              -E     prints full time-date stamps in the European `dd.mm.yyyy hh:mm' format
              -i     prints full time-date stamps in ISO8601 `yyyy-mm-dd hh:mm' format
              -t fmt prints time and date stamps in the given format; fmt is formatted with the strftime function with the zsh extensions described for the %D{string} prompt format in the
                     section EXPANSION OF PROMPT SEQUENCES in zshmisc(1).  The resulting formatted string must be no more than 256 characters or will not be printed
              -D     prints elapsed times; may be combined with one of the options above

              `fc -p' pushes the current history list onto a stack and switches to a new history list.  If the -a option is also specified, this history list will be automatically popped when
              the current function scope is exited, which is a much better solution than creating a trap function to call `fc -P' manually.  If no arguments are specified, the history list is
              left empty, $HISTFILE is unset, and $HISTSIZE & $SAVEHIST are set to their default values.  If one argument is given, $HISTFILE is set to that filename, $HISTSIZE & $SAVEHIST are
              left unchanged, and the history file is read in (if it exists) to initialize the new list.  If a second argument is specified, $HISTSIZE & $SAVEHIST are instead set to the single
              specified numeric value.  Finally, if a third argument is specified, $SAVEHIST is set to a separate value from $HISTSIZE.  You are free to change these environment values for the
              new history list however you desire in order to manipulate the new history list.

              `fc -P' pops the history list back to an older list saved by `fc -p'.  The current list is saved to its $HISTFILE before it is destroyed (assuming that $HISTFILE and $SAVEHIST
              are set appropriately, of course).  The values of $HISTFILE, $HISTSIZE, and $SAVEHIST are restored to the values they had when `fc -p' was called.  Note that this restoration can
              conflict with making these variables "local", so your best bet is to avoid local declarations for these variables in functions that use `fc -p'.  The one other guaranteed-safe
              combination is declaring these variables to be local at the top of your function and using the automatic option (-a) with `fc -p'.  Finally, note that it is legal to manually pop
              a push marked for automatic popping if you need to do so before the function exits.

              `fc -R' reads the history from the given file, `fc -W' writes the history out to the given file, and `fc -A' appends the history out to the given file.  If no filename is
              specified, the $HISTFILE is assumed.  If the -I option is added to -R, only those events that are not already contained within the internal history list are added.  If the -I
              option is added to -A or -W, only those events that are new since last incremental append/write to the history file are appended/written.  In any case, the created file will have
              no more than $SAVEHIST entries.

这些选项是如何工作的?我在 macosx monterey 上使用 zsh 5.8。

zsh command-history
  • 1 1 个回答
  • 197 Views

1 个回答

  • Voted
  1. Best Answer
    Govind Rai
    2022-02-22T16:29:12+08:002022-02-22T16:29:12+08:00

    Stéphane Chazelas 的评论让我得到了答案。使用type内置的 shell 发现我的 shell 的history命令不再指向history二进制文件,而是一个指向omz_history -f.

    ❯ type history
    history is an alias for omz_history -f
    

    这是使用 zsh 配置管理器 Oh My ZSH 的副产品。omz_history支持 zsh 的内置命令不支持的附加选项,history并提供类似于 bashhistory命令的行为。

    谢谢斯蒂芬·查泽拉斯!

    • 1

相关问题

  • 列出没有其他后缀文件的文件

  • 什么情况下路径中最先找到的可执行文件不会被使用

  • 符号链接所有点文件和目录

  • 如何在`zsh`中增加一个动态命名的变量

  • 为什么我不能在 zsh 中定义一个名为 path 的只读变量?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve