是否有一种方便的方法来编写要运行的 bash 脚本git bisect run
,其中使用的 bisect 命令本身就是一个 bash 函数?如果我的函数名为step
,则似乎git bisect run step
两者git bisect run bash -c step
都无法看到该函数。
我的脚本目前看起来像
function step {
# Do a bunch of steps here
}
if [[ $_ == $0 ]] # Test if the script is being sourced
then
git bisect start
git bisect bad bad-commit
git bisect good good-commit
git bisect run bash -c ". $0 && step"
git bisect log
fi
这使用了在传递给的命令中制作脚本源本身的粗俗技巧,git bisect run
这意味着我必须在尝试执行git bisect
命令之前检查脚本当前是否正在被获取。
我想我可以将 bash 函数拆分为一个单独的脚本,但是有更好的方法可以在一个文件中完成这一切吗?