我定义了几个helper函数,我只在一个特定的fish脚本中使用.我把它们放在包装函数中,但你仍然可以通过自动完成找到它们.
如何将它们隐藏起来自动完成并将其范围限制为private?
function outer
function inner_func
echo "I still find this function via automplete"
end
end
Run Code Online (Sandbox Code Playgroud)
Fish 没有私有功能,但未来版本可能会提供此功能.在此期间,请尝试使用以下技术,命名约定或两者.
functions -e function_name非常接近你需要的.您可以functions -e function_name在块结束之前使用它从全局范围中删除它.
function outer
function inner_func
echo "I still find this function via automplete."
echo "Not anymore!!"
functions -e inner_func
end
# Let's test this!
inner_func
end
$ outer
I still find this function via automplete.
Not anymore!!
$ inner_func
fish: Unknown command 'inner_func'
Run Code Online (Sandbox Code Playgroud)
_my_module_func_name这不会从全局范围中删除该功能,但是一般的良好做法是避免无意中覆盖现有功能.
在主函数文件(或其他函数内部的函数)中声明的函数仅在其父函数被调用至少一次之后inner_func才可用(这是鱼延迟函数自动加载),并且仅在该特定shell会话的持续时间内存在.