[英]Git aliases with arguments and fish shell
例如, Human Git别名包括一些带参数的函数
into = "!f() { B=$(git current-branch); git checkout $1; git pull; git merge $B --no-edit; }; f"
我无法在鱼类中找到类似的东西。
我可以创建一个鱼别名,比如称为git-into,它可以工作,但我宁愿有一个git别名,所以我不必记住哪些命令使用破折号,哪些使用空格。
用! fish -c STUFF" or "! bash -c STUFF
! fish -c STUFF" or "! bash -c STUFF
! fish -c STUFF" or "! bash -c STUFF
没有正确传递参数。
我该如何做到这一点
git into repository
会做相当于上面的脚本吗?
添加一个领先的“!” 别名确实意味着git在shell中运行它,但是这个shell在这里不是鱼。 它是在构建时作为SHELL_PATH给出的shell,很可能(并默认为)“/ bin / sh”。 并且由于git使用相同的shell来运行其他东西(例如寻呼机),它肯定应该是POSIX兼容的,它排除了鱼。
您用户选择的登录shell无关紧要。
所以你可以简单地使用原始代码,它应该工作。
或者,您可以将其放入$ PATH中名为git-into
(无结尾,正确的shebang-line和可执行位)的脚本中,当您调用git into
时,git会找到它。
如果你真的想在这里使用fish -c
,你将不得不处理两个略微不兼容的引用层,这不是我推荐的。
没有任何git current-branch
。
如果您想要当前分支名称:
# extract the current branch name
git branch | grep \* | cut -d ' ' -f2
# or
git rev-parse --abbrev-ref HEAD
# since you are already on the current branch all you need is pull & merge
# be aware that there can be conflicts
into = "!f() { git pull; git merge $B --no-edit; }; f"
如果你想传递参数和checkout不同的分支你已经在你的别名中拥有它
git checkout $1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.