history-search-multi-word/README.md

159 lines
5.7 KiB
Markdown
Raw Normal View History

# history-search-multi-word - zsh plugin
2017-02-15 07:48:06 +00:00
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Gitter](https://img.shields.io/gitter/room/zdharma-continuum/zinit.svg?style=flat-square)](https://gitter.im/zdharma-continuum/zinit)
2016-05-22 06:58:00 +00:00
Binds `Ctrl-R` to a widget that searches for multiple keywords in an `AND` fashion. In other words, you
can enter multiple words, and history entries that match all of them are returned. Additionally, search matches are syntax highlighted.
2016-05-22 06:58:00 +00:00
Video view on [asciinema](https://asciinema.org/a/88954). You can resize the video by pressing
`Ctrl-+` or `Cmd-+`.
2016-05-22 06:58:00 +00:00
2016-10-12 15:26:49 +00:00
[![asciicast](https://asciinema.org/a/88954.png)](https://asciinema.org/a/88954)
2016-05-22 07:07:34 +00:00
HSMW has a feature called **context viewing** see all occurrences of a command together with
surrounding commands:
2016-10-16 17:09:00 +00:00
2018-01-05 15:20:34 +00:00
[![asciicast](https://asciinema.org/a/155704.png)](https://asciinema.org/a/155704)
2016-10-16 17:09:00 +00:00
2018-08-04 15:33:04 +00:00
Set:
```bash
zstyle :plugin:history-search-multi-word reset-prompt-protect 1
2018-08-04 15:33:04 +00:00
```
In order to use `zle reset-prompt` in function calls (e.g. `sched`) in addition to plugins that hook up into Zshell by overloading Zle
widgets (e.g., `fast-syntax-highlighting`, `zsh-syntax-highlighting`,
`zsh-autosuggestions`), use `sched` :
2019-04-20 19:02:08 +00:00
```bash
2019-04-20 19:02:08 +00:00
PROMPT=%B%F{yellow}%D{%H:%M:%S}%B%b%f
schedprompt() {
zle && zle reset-prompt
sched +1 schedprompt
2019-04-20 19:02:08 +00:00
}
zmodload -i zsh/sched
schedprompt
```
To refresh the clock in prompt every second. The `reset-prompt-protect` zstyle should be `1`
for proper cooperation with HSMW. Or, you could use `zle .reset-prompt` (i.e., with the dot in
front) to call the original, not overloaded (e.g., F-Sy-H, zsh-autosuggestions, etc.) `reset-prompt` widget.
2016-09-20 06:46:46 +00:00
## Installation
The plugin is **plugin manager agnostic**.
To install, clone the `history-search-multi-word` repository and add the following snippet to your
`.zshrc`
2016-05-25 06:05:24 +00:00
```bash
source <LOCATION-WHERE-REPOSITORY >/history-search-multi-word.plugin.zsh
2016-06-09 07:24:27 +00:00
```
If using a plugin manager, then `Zinit` is recommended, but you can use any other too, and also
install with `Oh My Zsh` (by copying the directory to `~/.oh-my-zsh/custom/plugins`).
2016-06-09 07:24:27 +00:00
### [Zinit](https://github.com/zdharma-continuum/zinit)
2016-06-09 07:24:27 +00:00
Add the following snippet to your `.zshrc`:
2016-06-09 07:24:27 +00:00
```bash
zinit load zdharma-continuum/history-search-multi-word
```
2016-05-23 15:58:20 +00:00
Zinit will automatically handle cloning the plugin for you the next time you start zsh.
2016-05-23 15:58:20 +00:00
2016-06-09 07:26:17 +00:00
### Antigen
2016-05-22 07:07:34 +00:00
Add `antigen bundle zdharma-continuum/history-search-multi-word` to your `.zshrc` file. Antigen will
automatically handle cloning the plugin for you the next time you start zsh. You can also add the
plugin to a running zsh with `antigen bundle zdharma-continuum/history-search-multi-word` for
testing before adding it to your `.zshrc`.
2016-06-09 07:26:17 +00:00
### Oh-My-Zsh
1. `cd ~/.oh-my-zsh/custom/plugins`
1. `git clone git@github.com:zdharma-continuum/history-search-multi-word.git`
1. Add `history-search-multi-word` to your plugin list
2016-06-09 07:26:17 +00:00
### Zgen
```zsh
zgen load zdharma-continuum/history-search-multi-word
```
to your .zshrc file in the same place
you're doing your other `zgen load` calls in.
### [Sheldon](https://github.com/rossmacarthur/sheldon)
1. Run
```bash
sheldon add history-search-multi-word --github zdharma-continuum/history-search-multi-word
```
To add the `ctrl-R` keybinding, add the following snippet to your `.zshrc`
```bash
bindkey "^R" history-search-multi-word
```
### 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).
1. Add the following to your `.zshrc`
```bash
source /usr/share/zsh/plugins/history-search-multi-word/history-search-multi-word.plugin.zsh
```
1. Start a new terminal session via `exec zsh`
## Options
2016-05-22 19:27:39 +00:00
```bash
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 ":history-search-multi-word" page-size "8" # Number of entries to show (default is $LINES/3)
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)
zstyle ":plugin:history-search-multi-word" clear-on-cancel "no" # Whether pressing Ctrl-C or ESC should clear entered query
zstyle ":plugin:history-search-multi-word" synhl "yes" # Whether to perform syntax highlighting (default true)
2016-05-22 07:07:34 +00:00
```
### Syntax highlighting
Syntax highlighting is customized via `HSMW_HIGHLIGHT_STYLES` associative array. It has keys like
`reserved-word`, `alias`, `command`, `path`, etc., which are assigned with strings like
`fg=blue,bold` to configure how given elements are to be colored. If you assign this array before
or after loading `hsmw`, you will change the defaults. The complete list of available keys is
[at the beginning](https://github.com/zdharma-continuum/history-search-multi-word/blob/master/hsmw-highlight#L34-L62)
of `hsmw-highlight` file. Example `~/.zshrc` addition that sets `path` key paths that exist will
be highlighted with background magenta, foreground white, bold:
2016-10-12 14:30:44 +00:00
```bash
2016-10-12 14:30:44 +00:00
typeset -gA HSMW_HIGHLIGHT_STYLES
HSMW_HIGHLIGHT_STYLES[path]="bg=magenta,fg=white,bold"
```
#### Enable coloring of options of form "-o" and "--option", with cyan:
2016-10-13 06:46:09 +00:00
```zsh
typeset -gA HSMW_HIGHLIGHT_STYLES
HSMW_HIGHLIGHT_STYLES[double-hyphen-option]="fg=cyan"
HSMW_HIGHLIGHT_STYLES[single-hyphen-option]="fg=cyan"
2016-10-13 06:46:09 +00:00
```
#### 256 colors to highlight command separators (e.g., ;, &&, and ||):
2016-10-22 11:22:02 +00:00
```bash
2016-10-22 11:22:02 +00:00
HSMW_HIGHLIGHT_STYLES[commandseparator]="fg=241,bg=17"
```
<!-- vim:set ft=markdown tw=100 fo+=1n: -->