这是打破
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
有任何想法吗?
当我这样做时,它对我有用:
无论如何, “[: 1: unary operator expected”错误的最常见原因是您在 shell 脚本代码中具有如下所示:
if [ 1 = $MYVAL ]
而你MYVAL
的没有设置。检查您的完成功能。您可以添加set -x
以调试它。
通常最简单的解决方案是引用变量,这样操作员将得到空参数,但参数数量正确:
if [ 1 = "$MYVAL" ]
我也遇到了这个问题,每次谷歌搜索都会让我回到这篇文章。
我正在使用 Michal 的回答和 Daenyth 的评论发布我找到的解决方案......
我的 git-flow.bash 是相同的,但我认为我们的 git 完成文件可能会有所不同。
为了解决这个问题,我不得不修改我的 git 完成文件位于/etc/bash_completion.d/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
}
请注意我必须添加到新代码中的双括号。那是我所做的唯一改变。
为什么不只使用git-flow-completion?bash的说明是:
$ cd /etc/bash_completion.d
$ sudo wget https://raw.githubusercontent.com/bobthecow/git-flow-completion/master/git-flow-completion.bash
$ exec $SHELL
我有这个别名:
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
只需将 repo 中的二进制文件复制到~/bin