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

fish shell下初始化报错`fish: Unknown command: alias` #178

Closed Kosette closed 1 year ago

Kosette commented 1 year ago

fish shell version: 3.3.1 lua version: 5.4

在fish shell下初始化脚本的时候,报错fish: Unknown command: alias,把脚本中alias ${_ZL_CMD:-z}='_zlua'等两处地方改成fish的function形式:

function ${_ZL_CMD:-z}
    _zlua $argv
end

这样再source就不报错了。 fish对alias命令似乎从某个版本才开始兼容的,但奇怪的是我在一个更老的版本3.1.2上倒是可以直接使用的,fish shell的奇怪的兼容问题令人头疼。

ilyagr commented 1 year ago

I can only read this via Google Translate, but I think you are passing the bash/zsh script to fish. Does the problem happen if you do lua path/to/z.lua --init fish | source in fish?

Kosette commented 1 year ago

I can only read this via Google Translate, but I think you are passing the bash/zsh script to fish. Does the problem happen if you do lua path/to/z.lua --init fish | source in fish?

actually, i just pasted lua /path/to/z.lua --init fish | source to config.fish and nothing else. it threw out error imdediately when launching new shell or manually sourcing fish config file.

https://github.com/skywind3000/z.lua/blob/0992ebf9f1f6cdaa114e65d3aa76bfb1bd9a6fd4/z.lua#L2167 https://github.com/skywind3000/z.lua/blob/0992ebf9f1f6cdaa114e65d3aa76bfb1bd9a6fd4/z.lua#L2426

fish shell pointed out errors in these two lines. so i changed alias to fish shell function sytle and done. i did it on ubuntu 22.04, while on debian 11 all works well. so i think it's fish shell compatibility issue.

ilyagr commented 1 year ago

This is mysterious to me. The first of the lines you shared should not be run on fish shell, it's inside a sh script. The second line looks correct to me.

I'm just guessing, but maybe you set up z.lua for both bash and fish, and the configs somehow interfere with each other when fish is called from bash (or vice-versa)?

Also, perhaps you should try updating fish? I'm pretty sure I used the same config as you described since before fish 3.3.1, but perhaps I misremember, and now I'm on fish 3.6.

Kosette commented 1 year ago

Yes. Test on fish 3.6.1, works good. And i've checked the code again, you are right, just need to change the second one, i was misled by error prints. Pretty sure it's because the alias command not available in some fishshell versions.

Unfortunately the default version offered in official Ubuntu apt reposity is fish 3.3.1, people may get their fishshell directly from there other than from ppa repos. I will make a pr to fix this potential compatibilty issue.

Thanks for your help to point out the exact error code!