这是一个破损的标签
alias f='git flow feature'
complete -F __git_flow_feature f
最终它会起作用(需要2次“切换”),但每次“切换”都会抛出错误。
-bash: [: 1: unary operator expected
有什么想法吗?
这是一个破损的标签
alias f='git flow feature'
complete -F __git_flow_feature f
最终它会起作用(需要2次“切换”),但每次“切换”都会抛出错误。
-bash: [: 1: unary operator expected
$ cd /etc/bash_completion.d
$ sudo wget https://raw.githubusercontent.com/bobthecow/git-flow-completion/master/git-flow-completion.bash
$ exec $SHELL
当我执行以下操作时,可以使用它:
然而,“[: 1: unary operator expected”错误的最常见原因是在shell脚本代码中有这样的内容:
if [ 1 = $MYVAL ]
你的MYVAL
未设置。请检查您的完成函数。您可以添加set -x
进行调试。
通常最简单的解决方法是引用变量,这样操作符将获得空参数,但参数数量正确:
if [ 1 = "$MYVAL" ]
[[
而不是[
。它更加智能。 - Daenyth我也遇到了这个问题,每次谷歌搜索都会让我回到这篇文章。
我发现了解决方法,使用了Michal的答案和Daenyth的评论...
我的git-flow.bash与原帖相同,但我认为我们的git完成文件可能有所不同。
为了解决这个问题,我必须修改位于/etc/bash_completion.d/git
的git完成文件。
旧的:
# __git_find_on_cmdline requires 1 argument
__git_find_on_cmdline ()
{
local word subcommand c=1
while [ $c -lt $cword ]; do
word="${words[c]}"
for subcommand in $1; do
if [ "$subcommand" = "$word" ]; then
echo "$subcommand"
return
fi
done
c=$((++c))
done
}
新功能:
# __git_find_on_cmdline requires 1 argument
__git_find_on_cmdline ()
{
local word subcommand c=1
while [[ $c -lt $cword ]]; do
word="${words[c]}"
for subcommand in $1; do
if [ "$subcommand" = "$word" ]; then
echo "$subcommand"
return
fi
done
c=$((++c))
done
}
注意我必须添加的双括号到新代码中。这是我所做的唯一更改。
我有以下别名:
alias gn="git-number"
alias gb="gn -c git blame"
alias ge="gn -c $EDITOR"
alias ga="gn add"
alias gr="gn -c git reset"
alias gap="EDITOR='$EDITOR -w' gn add -p"
alias gd="gn -c git diff -b -w --ignore-blank-lines"
alias gds="gd --staged"
alias gc="gn -c git checkout"
alias gcf="git flow feature checkout"
alias gl="gn -c git log -w -b -p --ignore-blank-lines"
alias gls="git log --stat"
alias cm="EDITOR='$EDITOR -w' git commit"
alias grb="git stash save 'REBASE' && EDITOR='$EDITOR -w' git rebase -i"
alias grbc="EDITOR='$EDITOR -w' git rebase --continue"
gcd() {
test -n "$1" && cd $(dirname $(git list $1))
}
source ~/.git-completion.bash
__git_complete gn _git
__git_complete ga _git_add
__git_complete gap _git_add
__git_complete gd _git_diff
__git_complete gds _git_diff
__git_complete gc _git_checkout
__git_complete gcf _git_checkout
__git_complete gl _git_log
__git_complete gls _git_log
__git_complete cm _git_commit
source ~/.git-flow-completion.bash
并将 completion
脚本安装如下:
wget -O ~/.git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
wget -O ~/.git-flow-completion.bash https://raw.githubusercontent.com/petervanderdoes/git-flow-completion/develop/git-flow-completion.bash
这里记录的 Git 版本号是:https://github.com/holygeek/git-number。只需将存储库中的二进制文件复制到 ~/bin
目录即可。