skywind3000 / z.lua

:zap: A new cd command that helps you navigate faster by learning your habits.
MIT License
2.94k stars 137 forks source link

--init show zsh: parse error near `>&' #205

Closed alps2006 closed 2 months ago

alps2006 commented 2 months ago

A strange problem on z.lua --init

z.lua$ eval "$(lua z.lua --init)" 
# output error
zsh: parse error near `>&'

I found the error location at -h|--help) local arg_mode="-h" ;;, and i resolved by escaping --help , but why only --help?

M z.lua
@@ -2188,7 +2188,7 @@ _zlua() {
            -s) local arg_strip="-s" ;;
            -i) local arg_inter="-i" ;;
            -I) local arg_inter="-I" ;;
-           -h|--help) local arg_mode="-h" ;;
+           -h|\--help) local arg_mode="-h" ;;
            --purge) local arg_mode="--purge" ;;
            *) break ;;
        esac
skywind3000 commented 2 months ago

which version of zsh are you using? I haven't encountered this before in zsh.

alps2006 commented 2 months ago

Thanks for your reply, the detail is below.

~/Documents/markdown ❯ zsh  --version
zsh 5.9 (x86_64-apple-darwin23.0.0)
~/Documents/markdown ❯ type -a zsh
zsh is /opt/local/bin/zsh
zsh is /bin/zsh
zsh is /opt/local/bin/zsh
zsh is /bin/zsh
zsh is /opt/local/bin/zsh
skywind3000 commented 2 months ago

I am not sure if there is some side effect (mostly in other shells) when changing -- to \--. so I made another revise, please try out the latest version:

https://github.com/skywind3000/z.lua/commit/7c890c3645081014eab4be2ab45e8640f86f62d7

alps2006 commented 2 months ago

I have found the reason why i cannot use --help only, because there is a global alias that overrides --help entirely.

# bat to render --help
alias -g -- --help='--help 2>&1 | bat --language=help --style=plain'

thank you very much, i close it.