zsh-users / zsh-history-substring-search

🐠 ZSH port of Fish history search (up arrow)
2.59k stars 155 forks source link

Does not work with zinit #110

Open quasipedia opened 4 years ago

quasipedia commented 4 years ago

Describe the bug

Upon fresh installation and configuration of zinit and all the rest, the plugin does not work, and throw a no such file or directory error. This is the actual output (OMZ:: is just the zinit syntax to consume oh-my-zsh plugins). Other plugins (7 in total) work flawlessly.

Downloading `OMZ::plugins/history-substring-search/history-substring-search.plugin.zsh' (with curl, wget, lftp)...
/home/mac/.zinit/snippets/OMZ::plugins--history-substring-search/history-substring-search.plugin.zsh/history-substring-search.plugin.zsh:source:2: no such file or directory: /home/mac/.zinit/snippets/OMZ::plugins--history-substring-search/history-substring-search.plugin.zsh/history-substring-search.zsh

The functionality of the plugin is not there (so the error is not just cosmetic: the plugin does not work).

To Reproduce 1) Install zinit 2) In .zshrc att the following line: zinit snippet OMZ::plugins/history-substring-search/history-substring-search.plugin.zsh, save and exit. 3) Open a new terminal

Desktop (please complete the following information):

alichtman commented 4 years ago

I have it mostly working (with some minor bugs and inconsistencies) with:

$ cat ~/.zshrc
...
...

# Plugins {{{

source "$ZDOTDIR/.zinit/bin/zinit.zsh"

autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit

# oh-my-zsh plugins
zinit ice wait'!'
zinit snippet OMZ::lib/git.zsh
zinit ice wait'!'
zinit snippet OMZP::git
zinit ice wait'!'
zinit snippet OMZP::fzf
zinit ice wait'!'
zinit snippet OMZP::ssh-agent

# https://github.com/zdharma/zinit-configs/blob/a60ff64823778969ce2b66230fd8cfb1a957fe89/psprint/zshrc.zsh#L277
# Fast-syntax-highlighting & autosuggestions
zinit wait lucid for \
 atinit"ZINIT[COMPINIT_OPTS]=-C; zpcompinit; zpcdreplay" \
    zdharma/fast-syntax-highlighting \
 atload"!_zsh_autosuggest_start" \
    zsh-users/zsh-autosuggestions \
 blockf \
    zsh-users/zsh-completions

# GitHub Plugins
zinit ice wait'!'
zinit light zsh-users/zsh-history-substring-search

I have this in my ~/.zshenv:

...
# zinit
declare -A ZINIT
ZINIT[HOME_DIR]=$ZDOTDIR/.zinit
ZINIT[BIN_DIR]=$ZDOTDIR/.zinit/bin
ZINIT[PLUGINS_DIR]=$ZDOTDIR/.zinit/plugins
ZINIT[COMPLETIONS_DIR]=$ZDOTDIR/.zinit/completions
ZINIT[SNIPPETS_DIR]=$ZDOTDIR/.zinit/snippets
ZINIT[ZCOMPDUMP_PATH]=$XDG_CACHE_HOME/zcompdump
...
bricewge commented 4 years ago

With the PR #108 it's easier to get a configured zsh-history-substring-search working with zinit, it boils down to the following:

# Your configuration for the plugins
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#586e75'
export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=#d33682,fg=#002b36,bold'
export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=#dc322f,fg=#002b36,bold'
function _history_substring_search_config() {
    bindkey '^[[A' history-substring-search-up
    bindkey '^[[B' history-substring-search-down
}

# Syntax highlighting
zinit ice wait
zinit load zsh-users/zsh-syntax-highlighting
# NOTE The order is important here since it should be loaded before zsh-history-substring-search:
# https://github.com/zsh-users/zsh-history-substring-search#usage

# History substring search
zinit ice wait atload'_history_substring_search_config' \
  ver'dont-overwrite-config'
zinit load 'ericbn/zsh-history-substring-search'
# NOTE When #108 will be merged the three previous lines will be replaced by:
# zinit load 'zsh-users/zsh-history-substring-search'
# zinit ice wait atload'_history_substring_search_config'

Note than I'm not using OMZ here tho.

alichtman commented 4 years ago
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down

This isn't OS agnostic (only works on macOS for me, fails on Linux). You should use this syntax:

OS=$(uname -s)
if [ "$OS" = "Darwin" ]; then
    bindkey '^[[A' history-substring-search-up
    bindkey '^[[B' history-substring-search-down
elif [ "$OS" = "Linux" ]; then
    # https://superuser.com/a/1296543
    # key dict is defined in /etc/zsh/zshrc
    bindkey "$key[Up]" history-substring-search-up
    bindkey "$key[Down]" history-substring-search-down
fi

Edit: Updated syntax

bricewge commented 4 years ago

This isn't OS agnostic (only works on macOS for me, fails on Linux). You should use this syntax:

Looks like it's off-topic. The config was the more concise example I could conjure, see here and there for my actual configuration.

'^[[…' comes from the README. $key… doesn't work on my Linux system, it isn't OS agnostic at all since it's from a distro specific config not upstream zsh. If you want the widest compatible syntax, then use the terminfo module which is where the custom $key array gets it's values; this syntax is already present in the README.

alichtman commented 4 years ago

'^[[…' comes from the README

This was where I got the syntax for my config originally, which broke when I moved my config to Linux. Replacing these weird escape sequences with $key solved the problem. I believe I found the solution in one of the issues on this repo.

all since it's from a distro specific config not upstream zsh

The comment at the top of the file is just outdated (fixed in the last commit, thanks for pointing that out). I use this config on my Linux box daily.

And TIL that $key is an Ubuntu-specific feature of zsh and not included upstream.

I could have phrased my response better. All I meant was that if I had used $key or $terminfo, instead of hardcoding the escape sequences in, I would have had fewer issues migrating my config to different OSes. However, I'm now considering using $terminfo instead of $key for even better portability (that I thought I already had, hence my OS agnosticism comment before).

quasipedia commented 4 years ago

OP here. Still not really getting what I should do to have the plugin working. For what matters, the ${key[Up]} style of syntax works on fedora too, but I fail to understand the link between the solutions posted here and the error message, in which it appears the issue being the file name. Any help in understanding appreciated. :)

alichtman commented 4 years ago

Try initializing it like I do:

# GitHub Plugins
zinit ice wait'!'
zinit light zsh-users/zsh-history-substring-search

instead of using snippet

quasipedia commented 4 years ago

Thank you @alichtman ! Trying to do as you said prompts me for username and password for GitHub, which is weird (why would zinit want to know them to just clone a repo?) plus I do have ssh set up (why isn't zinit using that instead?). For me it worked by remixing your example with the ver'dont-overwrite-config' and using ericbn/zsh-history-substring-search instead of zsh-users/zsh-history-substring-search as suggested in @bricewge snippet.

Now it works, but... is the fact one must use this way to load it (as opposed to use a regular "snippet" as for all things OMZ) make me feel this issue is still valid (please correct me if I am mistaken).

Thanks both for your help! :)

EDIT: The only minor annoyance is that each time a new terminal windows loads, I got the message: Loaded ericbn/zsh-history-substring-search, but I can live with that. :)

alichtman commented 4 years ago

ericbn/zsh-history-substring-search

I would advise against using this fork (that's currently even with this repo), and use the master repo instead.

bricewge commented 4 years ago

[...] I got the message: Loaded ericbn/zsh-history-substring-search, but I can live with that. :)

@quasipedia To get rid of that message just add silent at the end of the line starting with zinit ice, you can read the documentation about it.

sunaku commented 3 years ago

Now that PR #108 is merged, can we close this issue?