ericfreese / zsh-prioritize-cwd-history

Prioritizes history entries executed from the current working directory
MIT License
21 stars 6 forks source link

Fix for "command not found" and hanging prompt... #5

Open sean- opened 4 years ago

sean- commented 4 years ago

Howdy. I'm finally making the change from tcsh to zsh and stumbled across this module, which I really like in concept, however, it appears to be broken out of the box for on macOS. I think.

$ exec zsh -f
$ source ~/.zsh/zsh-prioritize-cwd-history/zsh-prioritize-cwd-history.zsh
_zsh_prioritize_cwd_history_cwd_hist_entries:9: command not found: #
_zsh_prioritize_cwd_history_cwd_hist_entries:12: command not found: #
_zsh_prioritize_cwd_history_cwd_hist_entries:15: command not found: #
[ hangs indefinitely ]

I was able to fix this by removing the comments (I also applied a patch from a fork, which I think is appropriate). The command that zsh is hanging on is sed.

diff --git a/zsh-prioritize-cwd-history.zsh b/zsh-prioritize-cwd-history.zsh
index 0fe6c1d..9faee8b 100644
--- a/zsh-prioritize-cwd-history.zsh
+++ b/zsh-prioritize-cwd-history.zsh
@@ -66,20 +66,13 @@ _zsh_prioritize_cwd_history_cwd_hist_entries() {
    # history entries (that were saved with EXTENDED_HISTORY)
    # referenced by the histrefs file
    local pattern=$(
-       # Get last 1000 histrefs
        tail -1000 "$histrefs" |
-
-       # Prepend ": " to timestamps
        sed -e 's/^/\^: /' |
-
-       # Join lines with a pipe delimiter
        paste -s -d '\|' - |
-
-       # Format into grep `OR` with backslash pipe
        sed -e 's/\|/\\\|/g'
    )

-   grep "$pattern" "$HISTFILE"
+   grep -a "$pattern" < "$HISTFILE"
 }

 # Reads history entries executed in the current working directory into