Skip to content

z-shell/H-S-MW

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ZI logo ❮ Zi ❯ - H-S-MW (History Search Multi Word)

Binds Ctrl-R to search for multiple keywords.
History entries that match all keywords will be found and syntax highlighted.

ASCIInema Colored Zsh History – context of command demo

License (GPL version 3) ZSH v5.0.0


Customizing

Context viewing

See all occurrences of a command together with surrounding commands set:

zstyle :plugin:history-search-multi-word reset-prompt-protect 1

reset-prompt

Use zle reset-prompt in sched calls, in the presence of z-shell/F-Sy-H, zsh-users/zsh-syntax-highlighting, zsh-users/zsh-autosuggestions, and other plugins that hook up into Z-Shell by overloading ZLE widgets.

For example, to refresh the clock in prompt every second:

PROMPT=%B%F{yellow}%D{%H:%M:%S}%B%b%f
schedprompt() {
  zle && zle reset-prompt
  sched +1 schedprompt
}

zmodload -i zsh/sched
schedprompt

The reset-prompt-protect zstyle needs to be set to 1 for correct cooperation with H-S-MW.

Alternatively, you could use zle .reset-prompt (i.e. with the dot in front) to call the original, not an overloaded reset-prompt widget (created by F-Sy-H, zsh-autosuggestions, etc.).

Zstyles

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)
zstyle ":plugin:history-search-multi-word" clear-on-cancel "no"        # Whether pressing Ctrl-C or ESC should clear entered query

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. The complete list of available keys is at the beginning of functions/hsmw-highlight.

If you assign this array in ~/.zshrc before or after loading hsmw you will change the defaults.

Examples

Sets path key – paths that exist will be highlighted with background magenta, foreground white, bold
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
typeset -gA HSMW_HIGHLIGHT_STYLES
HSMW_HIGHLIGHT_STYLES[single-hyphen-option]="fg=cyan"
HSMW_HIGHLIGHT_STYLES[double-hyphen-option]="fg=cyan"
Use 256 colors to highlight command separators (like ";" or "&&")
HSMW_HIGHLIGHT_STYLES[commandseparator]="fg=241,bg=17"

Installation

The plugin is "standalone", which means that only sourcing it is needed. So to install, unpack H-S-MW somewhere and add to ~/.zshrc:

source {where-hsmw-is}/H-S-MW.plugin.zsh

If using a plugin manager, then Zi is recommended, but you can use others if you prefer:

Add zi load z-shell/H-S-MW to your ~/.zshrc file. Zi will handle cloning the plugin for you automatically the next time you start zsh.

Oh My Zsh (OMZ)

  1. Run this command to clone and mv to the ~/.oh-my-zsh/custom/plugins directory

    git clone https://github.com/z-shell/H-S-MW.git \
     ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/H-S-MW
  2. Add H-S-MW to your plugin list in the ~/.zshrc file

    plugins=(... H-S-MW)

Add zinit load z-shell/H-S-MW to your .zshrc file.

Add antigen bundle z-shell/H-S-MW to your .zshrc file. 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 z-shell/H-S-MW for testing before adding it to your .zshrc.

  1. Add zgen load z-shell/H-S-MW to your .zshrc file in the same place you're doing your other zgen load calls in.
  2. Start a new terminal session