Coder Social home page Coder Social logo

history-search-multi-word's Introduction

history-search-multi-word - zsh plugin

License: GPL v3 Gitter

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.

Video – view on asciinema. You can resize the video by pressing Ctrl-+ or Cmd-+.

asciicast

HSMW has a feature called context viewing – see all occurrences of a command together with surrounding commands:

asciicast

Set:

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

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 :

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 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.

Installation

The plugin is plugin manager agnostic.

To install, clone the history-search-multi-word repository and add the following snippet to your .zshrc

source <LOCATION-WHERE-REPOSITORY >/history-search-multi-word.plugin.zsh

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).

Add the following snippet to your .zshrc:

zinit load zdharma-continuum/history-search-multi-word

Zinit will automatically handle cloning the plugin for you the next time you start zsh.

Antigen

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.

Oh-My-Zsh

  1. cd ~/.oh-my-zsh/custom/plugins
  2. git clone [email protected]:zdharma-continuum/history-search-multi-word.git
  3. Add history-search-multi-word to your plugin list

Zgen

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.

  1. Run
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

bindkey "^R" history-search-multi-word

Arch Linux

  1. Install zsh-history-search-multi-word-git from the AUR.

  2. Add the following to your .zshrc

    source /usr/share/zsh/plugins/history-search-multi-word/history-search-multi-word.plugin.zsh
  3. Start a new terminal session via exec zsh

Options

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)

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 of hsmw-highlight file. Example ~/.zshrc addition that 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[double-hyphen-option]="fg=cyan"
HSMW_HIGHLIGHT_STYLES[single-hyphen-option]="fg=cyan"

256 colors to highlight command separators (e.g., ;, &&, and ||):

HSMW_HIGHLIGHT_STYLES[commandseparator]="fg=241,bg=17"

history-search-multi-word's People

Contributors

alichtman avatar hugoh avatar isac322 avatar kapsh avatar pschmitt avatar psprint avatar snaeil avatar unixorn avatar vladdoster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

history-search-multi-word's Issues

Alternative using fzf

Maybe interesting to you - an alias that seems to do essentially the same but interactively, though without syntax highlighting

alias hist='print -z $(history | tac | fzf --tiebreak=index | sed "s|^ \+||" | cut -d" " -f5-)'

[bug]: unable to remap keybindings

I like this plugin, but I want to change some of its keybindings. I tried changing the hsmw keymap with the changes I want, but as far as I can tell, they aren't being applied (and the keymap doesn't even exist before the history search is ever used). Is there some way to do so?

[bug]: key-bindings not created when using Sheldon

Many zdharma-continuum plugins seem to work with sheldon for zsh.

I love this plugin but I didn't get it to work with sheldon.

My plugins.toml for sheldon looks like this:

shell = "zsh"

[plugins]

[plugins.powerlevel10k]
github = 'romkatv/powerlevel10k'

[plugins.fast-syntax-highlighting]
github = 'zdharma-continuum/fast-syntax-highlighting'

[plugins.alias-tips]
github = 'djui/alias-tips'

[plugins.conda-zsh-completion]
github = 'esc/conda-zsh-completion'

[plugins.zsh-autosuggestions]
github = 'zsh-users/zsh-autosuggestions'
use = ["{{ name }}.zsh"]

[plugins.history-search-multi-word]
github = 'zdharma-continuum/history-search-multi-word'

[plugins.oh-my-zsh]
github = 'ohmyzsh/ohmyzsh'

Or am I missing something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.