mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
fix the history function and man page
The previous commit to add a `--with-timestamp` flag to the `history` command caused me to notice the history function didn't recognize the new long option. Neither did it recognize the short options for the builtin command. This change fixes both of those issues.
This commit is contained in:
parent
68e167d576
commit
cbee315b1b
2 changed files with 57 additions and 49 deletions
|
@ -2,8 +2,13 @@
|
||||||
|
|
||||||
\subsection history-synopsis Synopsis
|
\subsection history-synopsis Synopsis
|
||||||
\fish{synopsis}
|
\fish{synopsis}
|
||||||
history ( --merge | --save | --clear )
|
history ( -m | --merge )
|
||||||
history ( --search | --delete ) [ --prefix "prefix string" | --contains "search string" ]
|
history ( -s | --save )
|
||||||
|
history ( -l | --clear )
|
||||||
|
history ( -s | --search ) [ -t | --with-time ] [ -p "prefix string" | --prefix "prefix string" | -c "search string | --contains "search string" ]
|
||||||
|
history ( -d | --delete ) [ -t | --with-time ] [ -p "prefix string" | --prefix "prefix string" | -c "search string | --contains "search string" ]
|
||||||
|
history ( -t | --with-time )
|
||||||
|
history ( -h | --help )
|
||||||
\endfish
|
\endfish
|
||||||
|
|
||||||
\subsection history-description Description
|
\subsection history-description Description
|
||||||
|
@ -11,6 +16,7 @@ history ( --search | --delete ) [ --prefix "prefix string" | --contains "search
|
||||||
`history` is used to list, search and delete the history of commands used.
|
`history` is used to list, search and delete the history of commands used.
|
||||||
|
|
||||||
The following options are available:
|
The following options are available:
|
||||||
|
|
||||||
- `--merge` immediately incorporates history changes from other sessions. Ordinarily `fish` ignores history changes from sessions started after the current one. This command applies those changes immediately.
|
- `--merge` immediately incorporates history changes from other sessions. Ordinarily `fish` ignores history changes from sessions started after the current one. This command applies those changes immediately.
|
||||||
|
|
||||||
- `--save` saves all changes in the history file. The shell automatically saves the history file; this option is provided for internal use.
|
- `--save` saves all changes in the history file. The shell automatically saves the history file; this option is provided for internal use.
|
||||||
|
@ -25,6 +31,8 @@ The following options are available:
|
||||||
|
|
||||||
- `--contains` searches or deletes items in the history that contain the specified text string.
|
- `--contains` searches or deletes items in the history that contain the specified text string.
|
||||||
|
|
||||||
|
- `--with-time` prefixes the output of each displayed history entry with the time it was recorded in the format "%Y-%m-%d %H:%M:%S" in your local timezone.
|
||||||
|
|
||||||
\subsection history-examples Example
|
\subsection history-examples Example
|
||||||
|
|
||||||
\fish
|
\fish
|
||||||
|
|
|
@ -1,61 +1,61 @@
|
||||||
#
|
#
|
||||||
# Wrap the builtin history command to provide additional functionality.
|
# Wrap the builtin history command to provide additional functionality.
|
||||||
#
|
#
|
||||||
function history --shadow-builtin --description "Deletes an item from history"
|
function history --shadow-builtin --description "display or manipulate interactive command history"
|
||||||
set -l argc (count $argv)
|
if not set -q argv[1]
|
||||||
set -l prefix_args ""
|
# No arguments so execute history builtin using it's default behavior to display the entire
|
||||||
set -l contains_args ""
|
# history.
|
||||||
set -l cmd print
|
|
||||||
set -l search_mode none
|
|
||||||
set -l pager less
|
|
||||||
if set -q PAGER
|
|
||||||
set pager $PAGER
|
|
||||||
end
|
|
||||||
|
|
||||||
if test $argc -gt 0
|
|
||||||
for i in (seq $argc)
|
|
||||||
switch $argv[$i]
|
|
||||||
case --delete
|
|
||||||
set cmd delete
|
|
||||||
case --prefix
|
|
||||||
set search_mode prefix
|
|
||||||
set prefix_args $argv[(math $i + 1)]
|
|
||||||
case --contains
|
|
||||||
set search_mode contains
|
|
||||||
set contains_args $argv[(math $i + 1)]
|
|
||||||
case --save
|
|
||||||
set cmd save
|
|
||||||
case --clear
|
|
||||||
set cmd clear
|
|
||||||
case --search
|
|
||||||
set cmd print
|
|
||||||
case --merge
|
|
||||||
set cmd merge
|
|
||||||
case --help
|
|
||||||
set cmd help
|
|
||||||
case --
|
|
||||||
set -e argv[$i]
|
|
||||||
break
|
|
||||||
case "-*" "--*"
|
|
||||||
printf ( _ "%s: invalid option -- %s\n" ) history $argv[1] >&2
|
|
||||||
return 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# Execute history builtin without any argument.
|
|
||||||
if status --is-interactive
|
if status --is-interactive
|
||||||
builtin history | eval $pager
|
set -l pager less
|
||||||
|
set -q PAGER
|
||||||
|
and set pager $PAGER
|
||||||
|
builtin history --with-time | eval $pager
|
||||||
else
|
else
|
||||||
builtin history
|
builtin history
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set -l cmd search
|
||||||
|
set -l prefix_args ""
|
||||||
|
set -l contains_args ""
|
||||||
|
set -l search_mode none
|
||||||
|
set -l time_args
|
||||||
|
|
||||||
|
for i in (seq (count $argv))
|
||||||
|
switch $argv[$i]
|
||||||
|
case -d --delete
|
||||||
|
set cmd delete
|
||||||
|
case -v --save
|
||||||
|
set cmd save
|
||||||
|
case -l --clear
|
||||||
|
set cmd clear
|
||||||
|
case -s --search
|
||||||
|
set cmd search
|
||||||
|
case -m --merge
|
||||||
|
set cmd merge
|
||||||
|
case -h --help
|
||||||
|
set cmd help
|
||||||
|
case -t --with-time
|
||||||
|
set time_args --with-time
|
||||||
|
case -p --prefix
|
||||||
|
set search_mode prefix
|
||||||
|
set prefix_args $argv[(math $i + 1)]
|
||||||
|
case -c --contains
|
||||||
|
set search_mode contains
|
||||||
|
set contains_args $argv[(math $i + 1)]
|
||||||
|
case --
|
||||||
|
set -e argv[1..$i]
|
||||||
|
break
|
||||||
|
case "-*" "--*"
|
||||||
|
printf ( _ "%s: invalid option -- %s\n" ) history $argv[$i] >&2
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
switch $cmd
|
switch $cmd
|
||||||
case print
|
case search
|
||||||
# Print matching items. Note this may end up passing --search twice to the builtin,
|
builtin history $time_args --search $argv
|
||||||
# but that's harmless.
|
|
||||||
builtin history --search $argv
|
|
||||||
|
|
||||||
case delete
|
case delete
|
||||||
# Interactively delete history
|
# Interactively delete history
|
||||||
|
|
Loading…
Reference in a new issue