8

这是打破

alias f='git flow feature'
complete -F __git_flow_feature f

它最终会起作用(在 2 个“标签”之后),但在每次“标签”按下时都会引发错误。

-bash: [: 1: unary operator expected

有任何想法吗?

4

4 回答 4

2

当我这样做时,它对我有用:

  1. wget http://www.triquanta.nl/sites/default/files/git-flow.bash
  2. 源 git-flow.bash
  3. 别名 f='git 流功能'
  4. 完成 -F __git_flow_feature f
  5. Ftabtab

无论如何, “[: 1: unary operator expected”错误的最常见原因是您在 shell 脚本代码中具有如下所示:

if [ 1 = $MYVAL ] 

而你MYVAL的没有设置。检查您的完成功能。您可以添加set -x以调试它。

通常最简单的解决方案是引用变量,这样操作员将得到空参数,但参数数量正确:

if [ 1 = "$MYVAL" ] 
于 2012-01-17T15:42:02.687 回答
2

我也遇到了这个问题,每次谷歌搜索都会让我回到这篇文章。

我正在使用 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
}

请注意我必须添加到新代码中的双括号。那是我所做的唯一改变。

于 2013-01-22T00:05:37.900 回答
2

为什么不只使用git-flow-completionbash的说明是:

$ cd /etc/bash_completion.d
$ sudo wget https://raw.githubusercontent.com/bobthecow/git-flow-completion/master/git-flow-completion.bash
$ exec $SHELL

还有zshfish的说明。

于 2014-04-25T10:44:40.137 回答
1

我有这个别名:

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

于 2016-10-20T06:06:04.497 回答