私信  •  关注

joanis

joanis 最近创建的主题
joanis 最近回复了
6 年前
回复了 joanis 创建的主题 » 修改变量时出现bash脚本错误的git别名

这当然是一个必须在这里或那里逃离正确角色的情况。

我建议一个更简单的解决方案,也是由@user7369280建议的,同时我发布了这个答案的原始版本:create file git-auto-message 你路上的某个地方有这些内容:

#!/bin/bash

set -o errexit

current_branch="$(git rev-parse --abbrev-ref HEAD)"
no_feature=${current_branch##*/}
no_underscore=${no_feature%%_*}
history -s "git commit -m \"$no_underscore | "
echo "Press UP to start commit command:"
echo ""
read -e -p "> "
eval "$REPLY"

使此文件可执行

chmod 755 /path/to/git-auto-message

然后

git auto-message

将以与原始命令行相同的行为运行该脚本。

我刚刚对您的实际别名进行了故障排除,发现git别名语法不喜欢使用以下符号: # , > , | .

此变体可以工作,但会丢失一些功能:

  • 它不会删除分支名称开头的路径。我还没有找到一种方法来搜索 / 使用git别名接受的bash语法。
  • 它使用 - 而不是 γ 将分支名称与提交的其余部分分开。
  • 它使用 $ 而不是 > 为了提示。

修订别名:

auto-message = !bash -l -c 'current_branch="$(git rev-parse --abbrev-ref HEAD)" && no_feature=${current_branch} && no_underscore=${no_feature%%_*} && history -s "git commit -m $no_underscore - " && echo "Press UP to start commit command:" && echo "" && read -e -p "_ " && eval "$REPLY"'