Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Remove space added by completion
At 18:33 -0800 14 Feb 2014, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
On Feb 14,  7:49pm, Aaron Schrab wrote:
}
} I don't know about the original poster, but one place where I often
} don't want a space after a completion is with git branch names, to make
} it easier to do commands like:
}
}   # List commits in current branch but not in master
}   git log master..
}   # List commits from either branch which aren't in the other
}   git log branch1...branch2
Try something like the following; I won't hazard to commit it because
I don't know git branch syntax well enough yet.  With this diff you
should be able to complete the branch name and then type "." and it
will auto-remove the space.
That doesn't seem to work at all for me.  Looking at the code now, I see 
that the main place I'd want that behaviour (git log) isn't even 
completing branches.  It calls __git_commit_ranges, which in turn calls 
__git_commits which uses _alternative to call __git_heads to get 
branches and similar names as well as a couple of other functions to 
complete other ways to specify a commit.
That first function is already attempting to do this by passing `-qS ..` 
on towards compadd, but that doesn't get through _alternative.  If I 
modify it to instead call __git_heads directly (as in the diff below) it 
works.  But then that loses the ability to complete tags.
In the below patch I've also modified the additional arguments for 
compadd to work a bit better.  I changed the suffix to only a single dot 
rather than 2.  This allows typing one more dot to get the first form 
from my previous message; if two dots are supplied already it actually 
becomes harder to get that at the end of the range.  I also changed to 
remove the suffix if anything other than an alphanumeric follows.  This 
allows forms like `master~` or `branch@{1}` to be entered without 
needing to manually remove the dot.
If there's a way to get these arguments passed through the call to 
_alternative in __git_commits, I think it would be an improvement to 
change the actual arguments used.
diff --git c/Completion/Unix/Command/_git w/Completion/Unix/Command/_git
index 0c1288a..bf9417a 100644
--- c/Completion/Unix/Command/_git
+++ w/Completion/Unix/Command/_git
@@ -5499,7 +5499,7 @@ __git_commit_ranges () {
  if compset -P '*..(.|)'; then
    __git_commits $*
  else
-    __git_commits $* -qS ..
+    __git_heads $* -S . -r '^a-zA-Z0-9'
  fi
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author