zsh-users / zsh-history-substring-search

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

Not enough arguments for -U #154

Closed pro-sumer closed 4 months ago

pro-sumer commented 10 months ago

Recently I have been getting this error when trying to reuse commands from my zsh history:

_history-substring-search-end:zle:61: not enough arguments for -U

What am I doing wrong? Or what is broken?

lixiaoyan commented 10 months ago

same here

dxrcy commented 8 months ago

i get it too. specifically when i type - after pressing an up/down arrow key. it prints the message and doesn't add a - to the prompt, but everything works after that, and typing another - works as expected. until the next up/down arrow key.

aperum commented 7 months ago

The proposed fix only fixes the - case for me but not the <space> case which is much more annoying to me ;) Additionally quoting the argument helps:

--- a/zsh-history-substring-search.zsh
+++ b/zsh-history-substring-search.zsh
@@ -406,7 +406,7 @@ _history-substring-search-end() {

   # For debugging purposes:
   # zle -R "mn: "$_history_substring_search_match_index" m#: "${#_history_substring_search_matches}
-  # read -k -t 200 && zle -U $REPLY
+  # read -k -t 200 && zle -U -- "$REPLY"

   #
   # When this function returns, z-sy-h runs its line-pre-redraw hook. It has no
@@ -421,7 +421,7 @@ _history-substring-search-end() {
     # before removing search highlight and exiting. This ensures no highlights
     # are left lingering after search is finished.
     #
-    read -k -t ${HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_TIMEOUT:-1} && zle -U $REPLY
+    read -k -t ${HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_TIMEOUT:-1} && zle -U -- "$REPLY"
     region_highlight=( "${(@)region_highlight:#*${highlight_memo}*}" )
   fi
dxrcy commented 7 months ago

Can you explain how to reproduce the <space> case?

This change looks good regardless.

aperum commented 7 months ago

Just like the - case, press arrow up and then the space key. I get the same error as with -. I thought this was just another symptom of the same thing as with -. But after your question I investigated further with a minimal config and it seems the culprit is setopt SH_WORD_SPLIT. I added that years ago for compatability reasons. Maybe the plugin could unset that option for itself so that the users config does not interfere with its functionality.

dxrcy commented 7 months ago

I see. It seems that quoting the variable fixes it regardless, so I don't think we will need to unset SH_WORD_SPLIT.

xeruf commented 7 months ago

is the fix on its way? The error is quite obnoxious :sweat_smile:

dxrcy commented 7 months ago

@xeruf This will be fixed when #159 is merged. Until then, you can change the package url to github.com/dxrcy/zsh-history-substring-search

silverwind commented 4 months ago

change the package url to github.com/dxrcy/zsh-history-substring-search

Better to fork that fork again before using for security 😉.