skywind3000/z.lua

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

Kosette opened this issue · 4 comments

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的奇怪的兼容问题令人头疼。

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?

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.

z.lua/z.lua

Line 2167 in 0992ebf

alias ${_ZL_CMD:-z}='_zlua'

z.lua/z.lua

Line 2426 in 0992ebf

alias "$_ZL_CMD"=_zlua

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.

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.

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!