zsh になってから history コマンド打っても履歴の一部しか返ってこなくなった。。。
% history
313 history 1 3
314 history 1 4
315 history 0 4
316 history 1 25
317 history 11 10
318 history 11 20
319 history 11 2
320 history
321 history 300
322 history 300 310
323 history 300
324 history 315
325 history 320 315
326 history 0 4
327 history
328 history 0 4
上記のコマンドを実行した結果、直近から 16件しか返ってこない。
bash の頃は全件返ってきたような??
しかも、ヘルプも出てこない・・・
% history --help
history: bad option: -h
% history -h
history: bad option: -h
% history -?
zsh: no matches found: -?
man でも特に情報なし。
% man history
man zshbuiltins
で情報が出てくるとコメントいただきました!
ありがとうございます!
これだとあまり深い情報が出てこないので
% man zshbuiltins
で見る。
history
Same as fc -l.
とのことで、 fc のところを見ると色々書いてあります。
man の内容は最後に貼り付けておくとして、とりあえず分かったことをメモ。
オプション
スタートとエンドを指定する
オプションとして開始と終了を指定できる。
% history [start] [end]
全件表示したい
16件じゃなくて 全件出力したい場合、1 を渡せば全件返ってくる。
% history 1
範囲を指定する
特定の範囲を指定して取得することも可能。
% history 11 20
この場合は 11件目から 20件目までを出力可能。
降順で出力する
通常は昇順で出力されるが、 start > end で指定すると降順で出力できる。
% history 320 315
320 history
319 history 11 2
318 history 11 20
317 history 11 10
316 history 1 25
315 history 0 4
番号を指定して履歴から実行
![番号]
! の後に番号を指定して履歴からコマンドを実行可能。
これは特に zsh 関係ないですが。。。
% history
313 history 1 3
314 history 1 4
315 history 0 4
316 history 1 25
317 history 11 10
318 history 11 20
319 history 11 2
320 history
321 history 300
322 history 300 310
323 history 300
324 history 315
325 history 320 315
326 history 0 4
327 history
328 history 0 4
% !325
history 320 315
320 history
319 history 11 2
318 history 11 20
317 history 11 10
316 history 1 25
315 history 0 4
man zshbuiltins の fc
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 read-
ing and writing of history options is only performed if the shell is inter-
active. 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_HIS-
TORY 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 out-
put. Otherwise the editor program ename is invoked on a file containing
these history events. If ename 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' for-
mat
-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 ini-
tialize the new list. If a second argument is specified, $HISTSIZE & $SAVE-
HIST 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 his-
tory 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 guaran-
teed-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.