Giter Site home page Giter Site logo

zsh-history-substring-search's Introduction

zsh-history-substring-search

This is a clean-room implementation of the Fish shell's history search feature, where you can type in any part of any command from history and then press chosen keys, such as the UP and DOWN arrows, to cycle through matches.

Requirements

  • ZSH 4.3 or newer

Install

Using the Homebrew package manager:

brew install zsh-history-substring-search
echo 'source $(brew --prefix)/share/zsh-history-substring-search/zsh-history-substring-search.zsh' >> ~/.zshrc

Using Fig:

Fig adds apps, shortcuts, and autocomplete to your existing terminal.

Install zsh-history-substring-search in just one click.

Using Oh-my-zsh:

  1. Clone this repository in oh-my-zsh's plugins directory:

     git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
    
  2. Activate the plugin in ~/.zshrc:

     plugins=( [plugins...] zsh-history-substring-search)
    
  3. Run exec zsh to take changes into account:

     exec zsh
    

Using zplug:

  1. Add this repo to ~/.zshrc:

     zplug "zsh-users/zsh-history-substring-search", as: plugin
    

Using antigen:

  1. Add the antigen bundle command just before antigen apply, like this:
antigen bundle zsh-users/zsh-history-substring-search
antigen apply
  1. Then, after antigen apply, add the key binding configurations, like this:
# zsh-history-substring-search configuration
bindkey '^[[A' history-substring-search-up # or '\eOA'
bindkey '^[[B' history-substring-search-down # or '\eOB'
HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=1

Using Zinit:

  1. Use the Oh-my-zsh Zinit snippet in ~/.zshrc:

     zinit snippet OMZ::plugins/git/git.plugin.zsh`
    
  2. Load the plugin in ~/.zshrc:

     zinit load 'zsh-users/zsh-history-substring-search
     zinit ice wait atload'_history_substring_search_config'
    
  3. Run exec zsh to take changes into account:

     exec zsh
    

Usage

  1. Load this script into your interactive ZSH session:

    source zsh-history-substring-search.zsh
    

    If you want to use zsh-syntax-highlighting along with this script, then make sure that you load it before you load this script:

    source zsh-syntax-highlighting.zsh
    source zsh-history-substring-search.zsh
    
  2. Bind keyboard shortcuts to this script's functions.

    Users typically bind their UP and DOWN arrow keys to this script, thus:

    • Run cat -v in your favorite terminal emulator to observe key codes. ย  ย  ย (NOTE: In some cases, cat -v shows the wrong key codes. If the key codes shown by cat -v don't work for you, press <C-v><UP> and <C-v><DOWN> at your ZSH command line prompt for correct key codes.)

    • Press the UP arrow key and observe what is printed in your terminal.

    • Press the DOWN arrow key and observe what is printed in your terminal.

    • Press the Control and C keys simultaneously to terminate the cat -v.

    • Use your observations from the previous steps to create key bindings. For example, if you observed ^[[A for UP and ^[[B for DOWN, then:

      bindkey '^[[A' history-substring-search-up
      bindkey '^[[B' history-substring-search-down
      

      However, if the observed values don't work, you can try using terminfo:

      bindkey "$terminfo[kcuu1]" history-substring-search-up
      bindkey "$terminfo[kcud1]" history-substring-search-down
      

      Users have also observed that [OA and [OB are correct values, even if these were not the observed values. If you are having trouble with the observed values, give these a try.

      You might also want to bind the Control-P/N keys for use in EMACS mode:

      bindkey -M emacs '^P' history-substring-search-up
      bindkey -M emacs '^N' history-substring-search-down
      

      You might also want to bind the k and j keys for use in VI mode:

      bindkey -M vicmd 'k' history-substring-search-up
      bindkey -M vicmd 'j' history-substring-search-down
      
  3. Type any part of any previous command and then:

    • Press the history-substring-search-up key, which was configured in step 2 above, to select the nearest command that (1) contains your query and (2) is also older than the current command in your command history.

    • Press the history-substring-search-down key, which was configured in step 2 above, to select the nearest command that (1) contains your query and (2) is also newer than the current command in your command history.

    • Press ^U the Control and U keys simultaneously to abort the search.

  4. If a matching command spans more than one line of text, press the LEFT arrow key to move the cursor away from the end of the command, and then:

    • Press the history-substring-search-up key, which was configured in step 2 above, to move the cursor to the line above the cursored line. When the cursor reaches the first line of the command, pressing the history-substring-search-up key again will cause this script to perform another search.

    • Press the history-substring-search-down key, which was configured in step 2 above, to move the cursor to the line below the cursored line. When the cursor reaches the last line of the command, pressing the history-substring-search-down key, which was configured in step 2 above, again will cause this script to perform another search.

Configuration

This script defines the following global variables. You may override their default values.

  • HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND is a global variable that defines how the query should be highlighted inside a matching command. Its default value causes this script to highlight using bold, white text on a magenta background. See the "Character Highlighting" section in the zshzle(1) man page to learn about the kinds of values you may assign to this variable.

  • HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND is a global variable that defines how the query should be highlighted when no commands in the history match it. Its default value causes this script to highlight using bold, white text on a red background. See the "Character Highlighting" section in the zshzle(1) man page to learn about the kinds of values you may assign to this variable.

  • HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS is a global variable that defines how the command history will be searched for your query. Its default value causes this script to perform a case-insensitive search. See the "Globbing Flags" section in the zshexpn(1) man page to learn about the kinds of values you may assign to this variable.

  • HISTORY_SUBSTRING_SEARCH_FUZZY is a global variable that defines how the command history will be searched for your query. If set to a non-empty value, causes this script to perform a fuzzy search by words, matching in given order e.g. ab c will match *ab*c*

  • HISTORY_SUBSTRING_SEARCH_PREFIXED is a global variable that defines how the command history will be searched for your query. If set to a non-empty value, your query will be matched against the start of each history entry. For example, if this variable is empty, ls will match ls -l and echo ls; if it is non-empty, ls will only match ls -l.

  • HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE is a global variable that defines whether all search results returned are unique. If set to a non-empty value, then only unique search results are presented. This behaviour is off by default. An alternative way to ensure that search results are unique is to use setopt HIST_IGNORE_ALL_DUPS. If this configuration variable is off and setopt HIST_IGNORE_ALL_DUPS is unset, then setopt HIST_FIND_NO_DUPS is still respected and it makes this script skip duplicate adjacent search results as you cycle through them, but this does not guarantee that search results are unique: if your search results were "Dog", "Dog", "HotDog", "Dog", then cycling them gives "Dog", "HotDog", "Dog". Notice that the "Dog" search result appeared twice as you cycled through them. If you wish to receive globally unique search results only once, then use this configuration variable, or use setopt HIST_IGNORE_ALL_DUPS.

  • HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_TIMEOUT is a global variable that defines a timeout in seconds for clearing the search highlight.

History

  • September 2009: Peter Stephenson originally wrote this script and it published to the zsh-users mailing list.

  • January 2011: Guido van Steen (@guidovansteen) revised this script and released it under the 3-clause BSD license as part of fizsh, the Friendly Interactive ZSHell.

  • January 2011: Suraj N. Kurapati (@sunaku) extracted this script from fizsh 1.0.1, refactored it heavily, and finally repackaged it as an oh-my-zsh plugin and as an independently loadable ZSH script.

  • July 2011: Guido van Steen, Suraj N. Kurapati, and Sorin Ionescu (@sorin-ionescu) further developed it with Vincent Guerci (@vguerci).

  • March 2016: Geza Lore (@gezalore) greatly refactored it in pull request #55.

zsh-history-substring-search's People

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

Watchers

 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

zsh-history-substring-search's Issues

Wrong results with zsh-autosuggestions

I tried the suggestion here zsh-users/zsh-autosuggestions#7 (comment) to accept the suggestion with pressing "UP" arrow key (that triggers the history substring search plugin).

I type cd Scr and the suggestion becomes cd Scripts/bin.
I then press the "UP" arrow key to accept this, but instead it changes to another, completely unrelated command from history. What could be wrong?

I'm using zsh 5.0.4, zsh-history-substring-search commit 1e76804 and zsh-autosuggestions commit a29e838cdf.

down-key does not work

Platform version:

screen shot 2016-10-18 at 10 52 19 pm

However this:

# OPTION 2: for iTerm2 running on Apple MacBook laptops
zmodload zsh/terminfo
bindkey "$terminfo[cuu1]" history-substring-search-up
bindkey "$terminfo[cud1]" history-substring-search-down

seems to only partially work on my system: pressing down does nothing, but pressing up does work.

HIST_FIND_NO_DUPS causes most recent match to be skipped the second time around

When I enable the HIST_FIND_NO_DUPS option (see #19), if I first use the plugin to find the most recent match, subsequent invocations of the plugin find me the second-most-recent match first.

For example, enter these commands:

$ foo 1
$ foo 2

Then, typing foo<up> (with the ordinary bindings) at first correctly gives the completions in this order:

  1. foo 2
  2. foo 1

However, if you accept the first completion, foo 2, then invoke the plugin again by typing foo<up>, it skips directly to foo 1.

Implement fuzzy search

It would be nice to get this search working based on fuzzy search too. There's already a project that achieves this but the behaviour is slightly different. See https://github.com/junegunn/fzf. It would be nice to implement fzf in this plugin.

Stop depending on zsh-syntax-highlighting implementation details

Currently, this project defines the functions _zsh_highlight and _zsh_highlight_bind_widgets if they are not already available.

Those functions are private functions of zsh-syntax-highlighting, in its namespace, and z-sy-h reserves the right to change the semantics of those functions incompatibly without notice.

As a matter of good engineering, please stop depending on implementation details of z-sy-h.

if [[ $+functions[_zsh_highlight] -eq 0 ]]; then
#
# Dummy implementation of _zsh_highlight() that
# simply removes any existing highlights when the
# user inserts printable characters into $BUFFER.
#
_zsh_highlight() {
if [[ $KEYS == [[:print:]] ]]; then
region_highlight=()
fi
}
#
# The following snippet was taken from the zsh-syntax-highlighting project:
#
# https://github.com/zsh-users/zsh-syntax-highlighting/blob/56b134f5d62ae3d4e66c7f52bd0cc2595f9b305b/zsh-syntax-highlighting.zsh#L126-161
#
# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the zsh-syntax-highlighting contributors nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#--------------8<-------------------8<-------------------8<-----------------
# Rebind all ZLE widgets to make them invoke _zsh_highlights.
_zsh_highlight_bind_widgets()
{
# Load ZSH module zsh/zleparameter, needed to override user defined widgets.
zmodload zsh/zleparameter 2>/dev/null || {
echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2
return 1
}
# Override ZLE widgets to make them invoke _zsh_highlight.
local cur_widget
for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*)}; do
case $widgets[$cur_widget] in
# Already rebound event: do nothing.
user:$cur_widget|user:_zsh_highlight_widget_*);;
# User defined widget: override and rebind old one with prefix "orig-".
user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \
_zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \
zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
# Completion widget: override and rebind old one with prefix "orig-".
completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \
_zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \
zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
# Builtin widget: override and make it call the builtin ".widget".
builtin) eval "_zsh_highlight_widget_$cur_widget() { builtin zle .$cur_widget -- \"\$@\" && _zsh_highlight }; \
zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
# Default: unhandled case.
*) echo "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;;
esac
done
}
#-------------->8------------------->8------------------->8-----------------
_zsh_highlight_bind_widgets
fi

setopt ERR_RETURN breaks this plugin

I updated my plugin and it mostly stopped working. I suspect the re-factorings @gazalore because that's the biggest changeset. At least always when I search for something like "git push" I get any kinds of git commands and not only the "git push" commands as I expect.

For my own sanity, I forked this repo so new sudden changes doesn't disrupt me as easily again. In that repo I reverted to a version which seem to work. https://github.com/Tarrasch/zsh-history-substring-search

I apologize for not providing more details, but time will tell if others will report similar issues already or not.

Seg fault when using "HISTFILE=~/.zsh_history"

Hello,

as soon as I put HISTFILE=~/.zsh_history in my .zshrc, zsh seems to seg fault when zsh-history-substring-search is enabled.

It works quite when I comment out this one line.

Here's a .zshrc to reproduce the issue:

HISTFILE=~/.zsh_history

# Load zsh-syntax-highlighting plugin
. ${HOME}/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# Load zsh-history-substring-search
. ${HOME}/.zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh

# Load zsh-autosuggestions plugin
. ${HOME}/.zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

## zsh-autosuggestions
# use ctrl+T to toggle autosuggestions
bindkey '^T' autosuggest-toggle

## zsh-history-substring-search
# bind UP and DOWN arrow keys
zmodload zsh/terminfo
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
# bind P and N for EMACS mode
bindkey -M emacs '^P' history-substring-search-up
bindkey -M emacs '^N' history-substring-search-down
# bind k and j for VI mode
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
# OS X support
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down

I'm using the latest version (freshly cloned from this repository), by the way.

Let me know if you need any more information.

Inconsistent behaviour when zsh-syntax-highlighting is NOT sourced

I have not tested zsh-history-substring-search without using zsh-syntax-highlighting since quite some time. It seems to me that using zsh-history-substring-search without using zsh-syntax-highlighting causes some unexpected behavior:

user@machine ~> zsh -f -d
machine% source ./zsh-history-substring-search.zsh
machine% source [ARROW-UP]

After this I see:

machine% source ./zsh-history-substring-search.zsh

"source " is highlighted. "./zsh-history-substring-search.zsh" is not highlighted. The cursor is moved to the end of the command line. This is what I would expect.

However, if I press [ARROW-LEFT] now, the cursor moves, but all the previous highlighting is removed. This is unexpected, although it seems in line with the instructions in the source code. Anyway, it is not in line with the way ./zsh-history-substring-search.zsh behaves when syntax-highlighting is on.

user@machine ~> zsh -f -d
machine% source ./zsh-syntax-highlighting.zsh
machine% source ./zsh-history-substring-search.zsh
machine% source [ARROW-UP]

Again "source " is highlighted. "./zsh-history-substring-search.zsh" is not highlighted. The cursor is moved to the end of the command line. However, If I press [ARROW-LEFT] now, the cursor moves while the previous highlighting is preserved.

Is this intentional behaviour or is it a bug?

Guido

Preserving cursor position

I have a dream. [] is the cursor position.

$ for v in 1 2 3 ; do echo $v ; done[]
<enter>
1
2
3
$ []
<up-arrow>
$ for v in 1 2 3 ; do echo $v ; done[]
<move backwards to desired point
$ for v in 1 2 3 [] ; do echo $v ; done
<add 4>
$ for v in 1 2 3 4[] ; do echo $v ; done
<enter>
1
2
3
4
$ []

What do I desire happens next?

$ []
<up-arrow>
$ for v in 1 2 3 4[] ; do echo $v ; done

What actually happens?

$ []
<up-arrow>
$ for v in 1 2 3 4 ; do echo $v ; done[]

In short, I would like the last cursor position of that line to be remembered. Is this somehow possible? I spent quite some time looking how to accomplish this, but didn't find anything.

I believe this would be similar to readline's (which works for bash).

set history-preserve-point on

Color issue when used in tmux

Hello,

can someone help me out with this weird issue? At the moment, my history formatting looks like this:

bildschirmfoto 2015-02-09 um 10 13 37

When used in tmux however, it looks like this:

bildschirmfoto 2015-02-09 um 10 14 38

Can someone tell me how to get rid of the black "matching color"? I want it to be white like in my usual zsh shell as well.

โฏ  ~  echo $HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND; echo $HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND
bg=magenta,fg=white,bold
bg=red,fg=white,bold

Edit: Apparently I was using the wrong $TERM in my zshrc. After adding export TERM=xterm-256color It's black now without tmux as well.

Autoload script

Hi.
Thanks for this code. Its fantastic.
I am a little new to zsh. One thing I noticed is that adding the commands in the readme to .zshrc does not auto load the substring search each time I open a new shell terminal.
Can you tell me how I could get it to load automatically?
Thanks!

Use classic history search for a single letter

For example, I want to search a command that starts with "a", but substring searches almost every line which I don't need. I had to add another hotkey to use a history search which finds a selected letter.

I'm not a very good shell coder, could you help me to write this function?

Recover history expanders

As documented in this post on zsh, it's annoying when history expanders fail (causing the line with broken history expanders to be lost). The author proposes a way to fix it by modifying the standard zsh widgets:

function _recover_line_or_else() {
  if [[ -z $BUFFER && $CONTEXT = start && $zsh_eval_context = shfunc
        && -n $ZLE_LINE_ABORTED
        && $ZLE_LINE_ABORTED != $history[$((HISTCMD-1))] ]]; then
    LBUFFER+=$ZLE_LINE_ABORTED
    unset ZLE_LINE_ABORTED
  else
    zle .$WIDGET
  fi
}
zle -N up-line-or-history _recover_line_or_else
function _zle_line_finish() {
  ZLE_LINE_ABORTED=$BUFFER
}
zle -N zle-line-finish _zle_line_finish
  • Could a similar edit be made to zsh-history-substring-search?
  • Would this be a desirable feature to include?

not working with last zsh?

I've updated zsh (oh-my-zsh) maybe a week ago and it looks like the plugin doesn't work anymore?

I've got these plugins, could it be a conflict or something?

plugins=(git autojump node npm sublime history-substring-search compleat dircycle encode64 gem github osx urltools vagrant zsh-syntax-highlighting zsh-history-substring-search)

terminfo codes in README might not work in all cases?

On iTerm2 in OS X on my laptop, the arrow keys don't trigger the search functions when they are bound to $terminfo[kcuu1/kcud1], but do when they are bound to cuu1 and cud1.

According to the comment here, kcuu1/kcud1 refer to the arrow keys on the keypad. I'm not sure if this is just something unique to laptops or something, so I'm leaving it as an issue for now.

If I get time I might investigate further and see if switching would also work for desktops/full-sized keyboards.

Key Bindings

Should it bind itself, or should it allow the user to bind it manually, and if it should bind itself, should not it bind itself to more keys?

Right now, it only binds itself to the following sequences, which I believe are not valid for all terminals. There are also ^[OA, ^[OB, for example.

bindkey '\e[A' history-substring-search-up
bindkey '\e[B' history-substring-search-down

In my OMZ fork, I actually use $terminfo to get the sequences, but I also bind it to more keys.

bindkey -M emacs "^P" history-substring-search-up
bindkey -M emacs "^N" history-substring-search-down
bindkey -M vicmd "k" history-substring-search-up
bindkey -M vicmd "j" history-substring-search-down

for keymap in 'emacs' 'viins'; do
  bindkey -M "$keymap" '\e[A' history-substring-search-up
  bindkey -M "$keymap" '\e[B' history-substring-search-down
done
unset keymap

zsh-history-substring-search conflicts with zle yank-pop

I found zsh-history-substring-search (nor zsh-syntax-highlighting) doesn't work with zle's yank-pop.

Steps to reproduce the bug:

$ zsh -f
% bindkey -e
% hello # press <C-u> to kill the line
% bye # prees <C-u> again to add this line to the yank ring
# press <C-y> # 
% bye
# press <M-y> to rotate the elements on the yankring #
% hello
% source zsh-history-substring-search.zsh
# press <C-y>
% bye
# press <M-y>
% bye

$ zsh --version
zsh 5.0.0

I've tried to remap to see if it was a problem with the mapping but it doesn't work either.

Disable wrap-around?

Is it possible to disable wrap-around when I come to the end or beginning of history?

^R ?

Can you document how this differs from the behavior of history-incremental-search-backward ?

history-substring-search breaks url-quote-magic

With history-substring-search enabled, url-quote-magic doesn't work, as demonstrated by pasting http://example.com/foo?bar=baz into a zsh shell.

which url-quote-magic returns

url-quote-magic () {
        # undefined
        builtin autoload -XUz
}

I'm using zsh 4.3.17 (x86_64-unknown-linux-gnu) on Debian testing, with the version packaged for oh-my-zsh and the current trunk (sorin-ionescu's branch) of the latter (1515ff4b25d07da671b311ebd4b95497dc28aff7).

Can't get the plugin to work

I'm on OSX 10.9, zsh 5.0.5. I can't seem to get this plugin to work.

I'm not using any frameworks.

With my usual configuration, I'm loading the plugin with antigen at the end of my zshrc:

...
antigen bundle zsh-users/zsh-completions src
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle zsh-users/zsh-history-substring-search
...

And binding Up and Down arrows right after as described in the readme:

zmodload zsh/terminfo
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down

I also tried with zsh -l -f, sourcing the plugin:

source ~/.antigen/repos/...pluginrepo.../zsh-history-substring-search.zsh
zmodload zsh/terminfo
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down

(my zsh configuration for reference)

Thanks!

Use regular history search if the command line is empty

Right now, if I have nothing on the command line, I get an error saying that there are no matches. It would be more appropriate if the script falls back to regular history search if there is nothing on the command line.

zsh-history-substring-search not working with vi-mode (or simple bind -v)

I am a vim user and like the vi(m) mode for command line. I find that on both of my OS X installs, either adding the vi-mode plugin or just the bind -v to my zshrc causes the substring search to stop working (there are no errors thrown, it just simply doesn't work).

To aid in solving the issue, I am running the following plugins:

plugins=(git history history-substring-search macports osx python sublime tmux)

My tmux install is from macports.

Option to not show duplicates

I have the options HIST_IGNORE_DUPS and HIST_FIND_NO_DUPS set in Zsh, but the substring search plugin still shows duplicates when going back in history. Is there a way to filter out duplicates when using this plugin?

Pressing up prior to prompt being ready does not properly engage plugin behavior

I originally posted this on ohmyzsh/ohmyzsh#3857, but I realized that it belongs here, so I moved it.

Observe, if you run a long running process and type something that uses the shell's behavior, e.g. tab completion, as long as the process is not consuming stdin the shell will intelligently buffer your input for use when the prompt eventually arrives in the future.

For instance, zsh will tab complete globs when you hit tab. So if I type sleep 5 <ENTER> ls * <TAB>, what I will see is the shell waits for sleep to finish and then helpfully queues up my keystrokes, and ~3 seconds later I am automatically greeted by my prompt where i already have the contents of the current directory entered for me.

But the history-substring-search plugin does not apply this behavior properly. My aim here is to determine whether there is a systemic limitation that causes this unexpected behavior. When the shell prompt is being used normally, the plugin has perfect behavior. If the prompt is empty and I have not entered anything, then pressing up and down triggers the default behavior of fetching commands from history. Once I make an edit, though, the up and down keys trigger the plugin's search behavior using the contents of the command buffer to search.

The issue arises when I type commands during a long running process that does not consume input.

Suppose my command history at this point is this:

command A foo
command A bar
command B
command C
command D

(where command D is the long-running process not consuming input)

I type bar<Up> while D runs: zsh leaves my prompt on "command D". What I expect is the behavior I get if I type the same after D completes: "command A bar".

The behavior is that the part of the key queue that I typed prior to the movement key is discarded. I find that the best way to explain this is that the plugin behavior does not properly engage based on these queued up keystrokes.

If I disable the plugin and repeated the test, in both ways, I would get the same behavior because bar is essentially thrown away the moment that <Up> is pressed, in the absence of the plugin... this is standard default behavior.

So my Occam's Razor explanation of the problem is that the plugin's "edited buffer detection" feature is failing to produce a true value in the case of queued up keystrokes.

However, I tested some more and I discovered that if I bind pgup/pgdown keys to the plugin actions,

bindkey '^[[5~' history-substring-search-up
bindkey '^[[6~' history-substring-search-down

This actually works properly! This is confusing me because pgup/pgdown are by default also performing the same task in vanilla zsh, so the key conflict should still exist in this situation. The custom only-substring-search-if-buffer-is-edited behavior is still in effect as I use pgup/pgdn now, but any queued keystrokes prior to pressing pgup are now properly handled. This was definitely not expected and I cannot guess as to why this happens.

I was also hoping for a way to disable the only-substring-search-if-buffer-is-edited feature since I have demultiplexed the Up/Down keys at this point. But that is a separate topic.

Better antigen support

When using antigen, you get used to antigen bundle packagename and get package working. To use this plugin, some keybinding is needed.

It would be nice if running antigen bundle zsh-users/zsh-history-substring-search could get the plugin working, or at least leaving a note in the README for antigen users.

Multiline-buffer edit without search query

To reproduce :

  • call the widget until a multiline command appear (<UP>* x)
  • then move to prepare to enter it / exit search mode (<LEFT>* x)
  • move to enter in <UP>

Fails, we moved into next history entry instead of editing command.

This behavior only occurs when not using a search query. With a search query it behaves as expected.

Correct variable defining

I found some minor issue with this module, it's using global variables without typeset here: https://github.com/zsh-users/zsh-history-substring-search/blob/master/zsh-history-substring-search.zsh#L45-L48
So it warns with WARN_CREATE_GLOBAL option:

% loadmodule(){ source sh/zsh/zsh-history-substring-search.zsh };setopt WARN_CREATE_GLOBAL; loadmodule
sh/zsh/zsh-history-substring-search.zsh:45: scalar parameter HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND created globally in function loadmodule
sh/zsh/zsh-history-substring-search.zsh:46: scalar parameter HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND created globally in function loadmodule
sh/zsh/zsh-history-substring-search.zsh:47: scalar parameter HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS created globally in function loadmodule
sh/zsh/zsh-history-substring-search.zsh:48: scalar parameter HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE created globally in function loadmodule

These warnings can be fixed easily by prepending "typeset -g" before.

It's also warns when i'm calling it first time:

_history-substring-search-begin:3: scalar parameter _history_substring_search_refresh_display created globally in function _history-substring-search-begin
_history-substring-search-begin:4: scalar parameter _history_substring_search_query_highlight created globally in function _history-substring-search-begin
_history-substring-search-begin:18: scalar parameter _history_substring_search_result created globally in function _history-substring-search-begin
_history-substring-search-begin:34: scalar parameter _history_substring_search_query created globally in function _history-substring-search-begin
_history-substring-search-begin:50: array parameter _history_substring_search_raw_matches created globally in function _history-substring-search-begin
_history-substring-search-begin:67: scalar parameter _history_substring_search_raw_match_index created globally in function _history-substring-search-begin
_history-substring-search-begin:68: array parameter _history_substring_search_matches created globally in function _history-substring-search-begin
_history-substring-search-begin:93: scalar parameter _history_substring_search_match_index created globally in function _history-substring-search-begin

Don't know how to fix that yet

Up and down key not working

Hello. Up and down key seems to be not working. Whenever I press up and down key it seems that console simply shows the previous or next command relative to the currently shown command, not cycling through the matches to a given substring.

I checked cat -v to observe key codes for up and down key (^[[A and ^[[B for up and down key, respectively).

I use zplug to load this module together with zsh-syntax-highlighting. As instructed, I make sure that zsh-syntax-highlighting is loaded before zsh-history-substring-search.

zsh version I use is as follows:

$ zsh --version
zsh 5.1.1 (x86_64-ubuntu-linux-gnu)

my .zshrc is available here. Thanks in advance.

bad option: -F

When sourcing the file, I get this error:

zsh-history-substring-search.zsh:79: bad option: -F

Perhaps this is because I'm running an older version (4.2.6, on CentOS 5)?

Local history?

I would love to have a separate search for the shared history and one for the local terminal only. (I love history-substring-search, but I find it extremely annoying to have to search through history from a totally different context)

For example, it would be great if UP searches through the local history, while CTRL-UP searches through the shared one.

I tried to implement as described here:
http://superuser.com/questions/446594/separate-up-arrow-lookback-for-local-and-global-zsh-history

but this doesn't seem to work with history-substring-search. Any pointers?

strange problem with _history_substring_search_matches after failed search

Hi,

I occasionally stumble upon this problem, after search fails. In the example below, I typed 'open' and then did for backward search. Finally, I gave up, and tried up-arrow, which resulted in the first problem. The last error (after the empty line after prompt) is when I tried up-arrow on an empty line.

10080| dromi % open paper.tex                                                                                          
_history-substring-search-begin:30: no matches found: _history_substring_search_matches=(9847)
10080| dromi % open paper.tex                                                                                           
1| 10080| dromi % ope                                                                                                  
_history-substring-search-begin:30: bad pattern: _history_substring_search_matches=(149
1| 10080| dromi % ope                                                                                                  
1| 10080| dromi %                                                                                                       
_history-substring-search-begin:30: bad pattern: _history_substring_search_matches=(1

I'm using zsh-history-substring-search which is in oh-my-zsh.

gif

sorry about that, I accidentally created an issue. Please delete ๐Ÿ˜›

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.