How to enable autocomplete for a git -flow alias?

This is a violation

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

It works in the end (after 2 “tabs”), but it causes an error every time you press “tab”.

 -bash: [: 1: unary operator expected 

Any ideas?

+6
source share
4 answers

This works for me when I do this:

Anyway, the most common cause of the "[: 1: unary operator expected" error is what you have in your shell code, for example:

 if [ 1 = $MYVAL ] 

and your MYVAL not installed. Test your completion features. You can add set -x to debug it.

Usually the easiest solution is to quote the variable, so the operator will receive an empty argument, but will have the correct number of arguments:

 if [ 1 = "$MYVAL" ] 
+2
source

I had this problem too, and every google search led me to this post.

I am posting a solution that I found using Michal's answer and Daenyth's comment ...

My git -flow.bash was identical, but I think our git completion files may be different.

To fix this, I had to modify the git completion file located in /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 that I had to add to the new code. That was the only change I made.

+2
source

Why not just use git-flow-completion ? Instructions for bash:

 $ 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 .

+2
source

I have these 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 set the 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 marked here: https://github.com/holygeek/git-number Just copy the binaries to the repo on ~/bin

+1
source

Source: https://habr.com/ru/post/906192/


All Articles