zsh History 명령은 문서에 명시된 것보다 더 많은 옵션을 지원합니다.

zsh History 명령은 문서에 명시된 것보다 더 많은 옵션을 지원합니다.

zsh의 역사 명령은 -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을 사용하고 있습니다.

답변1

Stéphane Chazelas의 의견이 나에게 답을 주었다. type쉘 내장 기능을 사용하면 내 쉘 history명령이 더 이상 history바이너리를 가리키지 않고 대신 omz_history -f.

❯ type history
history is an alias for omz_history -f

이는 zsh 구성 관리자 Oh My ZSH 사용의 부산물입니다. zsh 내장 명령에서 지원되지 않는 추가 옵션을 omz_history지원 하고 bash 명령과 유사한 동작을 제공합니다.historyhistory

Stephen Chazeras에게 감사드립니다!

관련 정보