2017-02-15 08:48:06 +01:00
[![License (GPL version 3) ](https://img.shields.io/badge/license-GNU%20GPL%20version%203-blue.svg?style=flat-square )](./LICENSE)
[![MIT License ](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square )](./LICENSE)
![ZSH 5.0.0 ](https://img.shields.io/badge/zsh-v5.0.0-orange.svg?style=flat-square )
2021-11-12 18:28:53 +01:00
[![Gitter][gitter-image]][gitter-link]
2017-02-15 08:48:06 +01:00
2016-10-25 20:16:44 +02:00
# Introduction
2016-05-22 08:58:00 +02:00
Binds `Ctrl-R` to a widget that searches for multiple keywords in `AND` fashion.
In other words, you can enter multiple words, and history entries that match
2016-10-15 08:24:50 +02:00
all of them will be found. The entries are syntax highlighted.
2016-05-22 08:58:00 +02:00
2016-10-12 17:26:49 +02:00
Video – view on [asciinema ](https://asciinema.org/a/88954 ). You can resize the video by pressing `Ctrl-+` or `Cmd-+` .
2016-05-22 08:58:00 +02:00
2016-10-12 17:26:49 +02:00
[![asciicast ](https://asciinema.org/a/88954.png )](https://asciinema.org/a/88954)
2016-05-22 09:07:34 +02:00
2018-01-05 16:20:34 +01:00
HSMW has feature called **context viewing** – see all occurrences of a command together
with surrounding commands:
2016-10-16 19:09:00 +02:00
2018-01-05 16:20:34 +01:00
[![asciicast ](https://asciinema.org/a/155704.png )](https://asciinema.org/a/155704)
2016-10-16 19:09:00 +02:00
2018-08-04 17:33:04 +02:00
Set:
```zsh
zstyle :plugin:history-search-multi-word reset-prompt-protect 1
```
2019-04-20 21:02:08 +02:00
to be able to use `zle reset-prompt` in your e.g. `sched` calls, in presence of
2021-11-08 18:15:54 +01:00
`zdharma-continuum/fast-syntax-highlighting` , `zsh-users/zsh-syntax-highlighting` ,
2019-04-20 21:02:08 +02:00
`zsh-users/zsh-autosuggestions` and other plugins that hook up into Zshell by
overloading Zle widgets. You could e.g. use `sched` in following way:
```zsh
PROMPT=%B%F{yellow}%D{%H:%M:%S}%B%b%f
schedprompt() {
zle & & zle reset-prompt
sched +1 schedprompt
}
zmodload -i zsh/sched
schedprompt
```
to refresh the clock in prompt every second. The `reset-prompt-protect` zstyle
needs to be set to 1 for correct cooperation with HSMW. Or, you could use `zle
.reset-prompt` (i.e. with the dot in front) to call the original, not
overloaded (by F-Sy-H, zsh-autosuggestsions, etc.) `reset-prompt` widget.
2018-08-04 17:33:04 +02:00
2016-10-25 20:16:44 +02:00
# News
2020-07-14 21:16:26 +02:00
* 14-07-2020
- If an `[…]` string will occur in the search query, it'll be interpreted as
pattern. So that it's possible to enter as the search query e.g.: `print
["a-zA-Z0-9_-]` or ` print [^[:alpha:]]`, etc.
2019-10-28 14:25:43 +01:00
* 28-10-2019
- `^` – if first – matches beginning of the command's string, $ – if last –
its end. So that it's possible to enter `'^ls'` and have only commands
starting with `ls` matched.
2018-05-25 17:18:31 +02:00
* 25-05-2018
- Hash holding paths that shouldn't be grepped (globbed) – blacklist for slow disks, mounts, etc.:
```zsh
typeset -gA FAST_BLIST_PATTERNS
FAST_BLIST_PATTERNS[/mount/nfs1/*]=1
FAST_BLIST_PATTERNS[/mount/disk2/*]=1
```
2016-10-27 16:40:13 +02:00
2017-06-13 07:23:59 +02:00
* 13-06-2017
- Canceling search doesn't clear entered query. Change to previous behavior via:
```zsh
zstyle ":plugin:history-search-multi-word" clear-on-cancel "yes"
```
2017-04-12 09:13:31 +02:00
* 12-04-2017
- Page size can be relative to screen height, e.g.:
```zsh
zstyle ":history-search-multi-word" page-size "LINES/4"
```
2017-04-05 10:14:43 +02:00
* 05-04-2017
- 17% performance optimization
2017-01-27 13:08:52 +01:00
* 27-01-2017
- Input-driven case-sensivity of search – if your query contains capital latin letters, search will be case-sensitive
2016-11-12 16:40:37 +01:00
* 12-11-2016
- HSMW can now show context of selected history entry! Just hit `Ctrl-K` , [video ](https://asciinema.org/a/92516 )
- More performance optimizations
2016-10-31 14:56:28 +01:00
* 31-10-2016
2016-11-05 08:03:58 +01:00
- Newlines do not disturb the parser anymore, and are also highlighted with a dark color – [video ](https://asciinema.org/a/91159 )
2016-10-31 14:56:28 +01:00
2016-10-27 16:39:15 +02:00
* 27-10-2016
- New optimizations – **30%** speed up of syntax highlighting!
2016-10-27 16:40:13 +02:00
- Architectural change – syntax highlighting is now computed rarely, so any possible performance problems are now solved, in advance!
2016-10-27 16:39:15 +02:00
2016-10-24 10:04:01 +02:00
* 24-10-2016
2016-10-24 10:08:55 +02:00
- Workaround for Zsh versions like 5.0.2 has been added – **Ctrl-V** and **ESC** cancel search. On such Zsh
2016-10-24 10:04:01 +02:00
versions Ctrl-C might not work. Fully problem-free Zsh version will be the upcoming 5.3, where
I have together with Zsh Hackers fully fixed the Ctrl-C issue.
2016-10-22 11:59:58 +02:00
* 22-10-2016
- Search process has been optimized by 20%! History sizes like 100000 are now supported.
- Active history entry can be `underline` , `standout` (i.e. inverse video), `bold` , `bg=blue` , etc. with
2016-10-22 12:53:27 +02:00
the new Zstyle `:plugin:history-search-multi-word / active` (see Zstyles section) – [video ](https://asciinema.org/a/90214 ).
2016-10-22 11:59:58 +02:00
2016-10-16 19:09:00 +02:00
* 16-10-2016
2016-10-22 12:01:03 +02:00
- More optimizations of syntax highlighting (40% in total for the two days) – new video above.
2016-10-16 19:09:00 +02:00
2016-10-15 14:46:44 +02:00
* 15-10-2016
- The compact, already optimized (by me) [zsh-syntax-highlighting ](https://github.com/zsh-users/zsh-syntax-highlighting ) part has been further optimized by 21%!
Also, more tokens are highlighted – variable expressions like `"${(@)var[1,3]}"` (when quoted).
2016-05-25 08:05:24 +02:00
2016-10-11 09:28:05 +02:00
* 11-10-2016
2016-10-15 08:24:50 +02:00
- Syntax highlighting of history – adapted, fine crafted, **small** part of [zsh-syntax-highlighting ](https://github.com/zsh-users/zsh-syntax-highlighting )
2016-10-11 09:28:05 +02:00
to color what `hsmw` shows:
![syntax highlighting ](http://imagizer.imageshack.us/a/img921/1503/bMAF59.gif )
2016-09-20 08:46:46 +02:00
* 20-09-2016
2016-09-20 09:07:48 +02:00
- Keys Page Up and Page Down work and page-wise move along history. Also, `Ctrl-P` , `Ctrl-N`
2016-10-22 11:59:58 +02:00
move to previous and next entries.
2016-09-20 08:46:46 +02:00
2016-09-19 16:22:17 +02:00
* 19-09-2016
2016-09-20 08:46:46 +02:00
- Better immunity to [zsh-autosuggestions ](https://github.com/zsh-users/zsh-autosuggestions )
2016-09-19 16:42:44 +02:00
and [zsh-syntax-highlighting ](https://github.com/zsh-users/zsh-syntax-highlighting ) – home,
2016-10-22 11:59:58 +02:00
end, left and right cursor keys now work smoothly.
2016-09-19 16:22:17 +02:00
2016-05-25 08:05:24 +02:00
* 25-05-2016
- Cooperation with
[zsh-autosuggestions ](https://github.com/zsh-users/zsh-autosuggestions )
plugin
2016-05-25 09:24:03 +02:00
- Configuration option to set page size, example use:
```zsh
zstyle ":history-search-multi-word" page-size "5"
```
2016-05-25 08:05:24 +02:00
2016-10-25 20:16:44 +02:00
# Installation
2016-05-22 09:07:34 +02:00
2016-09-13 18:00:18 +02:00
**The plugin is "standalone"**, which means that only sourcing it is needed. So to
2016-06-09 09:24:27 +02:00
install, unpack `history-search-multi-word` somewhere and add
```zsh
source {where-hsmw-is}/history-search-multi-word.plugin.zsh
```
to `zshrc` .
2021-11-08 18:15:54 +01:00
If using a plugin manager, then `Zinit` is recommended, but you can use any
2016-06-09 09:24:27 +02:00
other too, and also install with `Oh My Zsh` (by copying directory to
`~/.oh-my-zsh/custom/plugins` ).
2021-11-08 18:15:54 +01:00
### [Zinit](https://github.com/zdharma-continuum/zinit)
2016-05-23 17:58:20 +02:00
2021-11-08 18:15:54 +01:00
Add `zinit load zdharma-continuum/history-search-multi-word` to your `.zshrc` file.
Zinit will handle cloning the plugin for you automatically the next time you
2016-05-23 17:58:20 +02:00
start zsh.
2016-06-09 09:26:17 +02:00
### Antigen
2016-05-22 09:07:34 +02:00
2021-11-08 18:15:54 +01:00
Add `antigen bundle zdharma-continuum/history-search-multi-word` to your `.zshrc` file.
2016-05-23 17:58:20 +02:00
Antigen will handle cloning the plugin for you automatically the next time you
start zsh. You can also add the plugin to a running zsh with `antigen bundle
2021-11-08 18:15:54 +01:00
zdharma-continuum/history-search-multi-word` for testing before adding it to your
2016-05-23 17:58:20 +02:00
`.zshrc` .
2016-05-22 11:58:11 -07:00
2016-06-09 09:26:17 +02:00
### Oh-My-Zsh
2016-05-22 11:58:11 -07:00
1. `cd ~/.oh-my-zsh/custom/plugins`
2021-11-08 18:15:54 +01:00
2. `git clone git@github.com:zdharma-continuum/history-search-multi-word.git`
2016-09-13 18:00:18 +02:00
3. Add `history-search-multi-word` to your plugin list
2016-05-22 11:58:11 -07:00
2016-06-09 09:26:17 +02:00
### Zgen
2016-05-22 11:58:11 -07:00
2021-11-08 18:15:54 +01:00
Add `zgen load zdharma-continuum/history-search-multi-word` to your .zshrc file in the same
2016-09-13 18:00:18 +02:00
place you're doing your other `zgen load` calls in.
2016-05-22 11:58:11 -07:00
2018-08-03 16:22:19 +09:00
### Arch Linux
1. Install [`zsh-history-search-multi-word-git` ](https://aur.archlinux.org/packages/zsh-history-search-multi-word-git/ ) from the [AUR ](https://wiki.archlinux.org/index.php/Arch_User_Repository ).
2. Add the following to your `.zshrc` :
```sh
source /usr/share/zsh/plugins/history-search-multi-word/history-search-multi-word.plugin.zsh
```
3. Start a new terminal session
2016-10-25 20:16:44 +02:00
# Customizing
2016-05-22 21:27:39 +02:00
2016-10-25 20:16:44 +02:00
## Zstyles
2016-05-22 21:27:39 +02:00
2016-05-22 09:07:34 +02:00
```zsh
Zstyle to configure whether to check paths for existence
parse.zsh -oo, after changes:
Running time: 1.5653990000
num calls time self name
-----------------------------------------------------------------------------------
1) 350 1557,37 4,45 99,99% 1199,04 3,43 76,98% -hsmw-highlight-process
2) 2800 294,91 0,11 18,93% 294,91 0,11 18,93% -hsmw-highlight-string
3) 1750 40,81 0,02 2,62% 40,81 0,02 2,62% -hsmw-highlight-check-path
4) 1400 22,61 0,02 1,45% 22,61 0,02 1,45% -hsmw-highlight-main-type
5) 1 0,12 0,12 0,01% 0,12 0,12 0,01% -hsmw-highlight-fill-option-variables
6) 1 0,02 0,02 0,00% 0,02 0,02 0,00% -hsmw-highlight-init
2016-11-05 11:36:03 +01:00
zstyle ":history-search-multi-word" page-size "8" # Number of entries to show (default is $LINES/3)
zstyle ":history-search-multi-word" highlight-color "fg=yellow,bold" # Color in which to highlight matched, searched text (default bg=17 on 256-color terminals)
zstyle ":plugin:history-search-multi-word" synhl "yes" # Whether to perform syntax highlighting (default true)
zstyle ":plugin:history-search-multi-word" active "underline" # Effect on active history entry. Try: standout, bold, bg=blue (default underline)
zstyle ":plugin:history-search-multi-word" check-paths "yes" # Whether to check paths for existence and mark with magenta (default true)
2017-06-13 07:23:59 +02:00
zstyle ":plugin:history-search-multi-word" clear-on-cancel "no" # Whether pressing Ctrl-C or ESC should clear entered query
2016-05-22 09:07:34 +02:00
```
2016-10-25 20:16:44 +02:00
## Syntax highlighting
2016-10-12 16:23:42 +02:00
Syntax highlighting is customized via `HSMW_HIGHLIGHT_STYLES` associative array.
2018-01-05 16:24:46 +01:00
It has keys like `reserved-word` , `alias` , `command` , `path` , etc. which are assigned
2016-10-12 16:23:42 +02:00
with strings like `fg=blue,bold` , to configure how given elements are to be
2018-01-05 16:24:46 +01:00
colored. If you assign this array before or after loading `hsmw` you will change the defaults. Complete list
2021-11-08 18:15:54 +01:00
of available keys is [at the beginning ](https://github.com/zdharma-continuum/history-search-multi-word/blob/master/hsmw-highlight#L34-L62 )
2016-10-12 16:30:44 +02:00
of `hsmw-highlight` file. Example `~/.zshrc` addition that sets `path` key –
2016-10-12 17:46:55 +02:00
paths that exist will be highlighted with background magenta, foreground white, bold:
2016-10-12 16:30:44 +02:00
```zsh
typeset -gA HSMW_HIGHLIGHT_STYLES
HSMW_HIGHLIGHT_STYLES[path]="bg=magenta,fg=white,bold"
```
2016-10-12 16:23:42 +02:00
2016-10-13 08:46:09 +02:00
Following code will enable coloring of options of form "-o" and "--option", with cyan:
```zsh
typeset -gA HSMW_HIGHLIGHT_STYLES
HSMW_HIGHLIGHT_STYLES[single-hyphen-option]="fg=cyan"
HSMW_HIGHLIGHT_STYLES[double-hyphen-option]="fg=cyan"
```
2016-10-22 13:22:02 +02:00
Following code will use 256 colors to highlight command separators (like ";" or "& & "):
```zsh
HSMW_HIGHLIGHT_STYLES[commandseparator]="fg=241,bg=17"
```
2021-11-12 18:28:53 +01:00
[gitter-image]: https://badges.gitter.im/zdharma-continuum/community.svg
[gitter-link]: https://gitter.im/zdharma-continuum/community