Skip to content

Commit

Permalink
[Search history] Make date time format configurable (#299)
Browse files Browse the repository at this point in the history
Enable configuring the format of command execution times in Search History through the new fzf_history_time_format variable. This is highly valuable for non-US users who may be accustomed to reading dates as day-month (rather than month-day as the default is), or for people who want to search through previous years of command history.
  • Loading branch information
tamirzb authored Jun 26, 2023
1 parent c5e1707 commit db5a67a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ set fzf_git_log_format "%H %s"

The format must be one line per commit and the hash must be the first field, or else Search Git Log will fail to determine which commits you selected.

### Change the date time format used by Search History

[Search History][] shows the date time each command was executed. To change how its formatted, set your [strftime format string](https://devhints.io/strftime) in `fzf_history_time_format`. For example, this shows the date time as DD-MM-YY:

```fish
set fzf_history_time_format %d-%m-%y
```

Do not to include the vertical box-drawing character `β”‚` (not to be confused with the pipe character `|`) as it is relied on to delineate the date time from the command.

## Further reading

Find answers to these questions and more in the [project Wiki](https://github.com/PatrickF1/fzf.fish/wiki):
Expand Down
12 changes: 8 additions & 4 deletions functions/_fzf_search_history.fish
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ function _fzf_search_history --description "Search command history. Replace the
builtin history merge
end

if not set --query fzf_history_time_format
# Reference https://devhints.io/strftime to understand strftime format symbols
set -f fzf_history_time_format "%m-%d %H:%M:%S"
end

# Delinate commands throughout pipeline using null rather than newlines because commands can be multi-line
set -f commands_selected (
# Reference https://devhints.io/strftime to understand strftime format symbols
builtin history --null --show-time="%m-%d %H:%M:%S β”‚ " |
builtin history --null --show-time="$fzf_history_time_format β”‚ " |
_fzf_wrapper --read0 \
--print0 \
--multi \
--tiebreak=index \
--prompt="Search History> " \
--query=(commandline) \
--preview="echo -- {4..} | fish_indent --ansi" \
--preview="echo -- {} | string replace --regex '^.*? β”‚ ' '' | fish_indent --ansi" \
--preview-window="bottom:3:wrap" \
$fzf_history_opts |
string split0 |
# remove timestamps from commands selected
string replace --regex '^\d\d-\d\d \d\d:\d\d:\d\d β”‚ ' ''
string replace --regex '^.*? β”‚ ' ''
)

if test $status -eq 0
Expand Down

0 comments on commit db5a67a

Please sign in to comment.