Reputation: 248
This is breaking
alias f='git flow feature'
complete -F __git_flow_feature f
It works eventually (after 2 'tabs') but throws an error on each 'tab' press.
-bash: [: 1: unary operator expected
Any ideas?
Upvotes: 8
Views: 2644
Reputation: 2198
Why don't just use git-flow-completion? The instructions for bash are:
$ cd /etc/bash_completion.d
$ sudo wget https://raw.githubusercontent.com/bobthecow/git-flow-completion/master/git-flow-completion.bash
$ exec $SHELL
there are also instructions for zsh or fish.
Upvotes: 3
Reputation: 25153
I have this aliases:
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
And install completion
scripts as:
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 number noted here is: https://github.com/holygeek/git-number
Just copy binaries at repo to ~/bin
Upvotes: 1
Reputation: 659
I had this problem too and every Google search lead me back to this post.
I am posting the solution I found using Michal's answer and Daenyth's comment...
My git-flow.bash was identical, but I think our git completion files might be varying.
To fix this I had to modify my git completion file located at /etc/bash_completion.d/git
Old:
# __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
}
New:
# __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
}
Notice the double bracket I had to add to the new code. That was the only change I made.
Upvotes: 2
Reputation: 31182
It works for me, when I do:
Anyhow, the most common reason for the "[: 1: unary operator expected" error is that you have in the shell script code like:
if [ 1 = $MYVAL ]
and your MYVAL
is not set. Inspect your completion functions. You can add set -x
to debug it.
Usually the easiest solution is to quote the variable so the operator will get the empty argument, but will have correct number of arguments:
if [ 1 = "$MYVAL" ]
Upvotes: 2