From 9e6c436d548eed8bfd24015e430824e0919bffff Mon Sep 17 00:00:00 2001 From: Ruben Berenguel Date: Tue, 29 Aug 2017 21:36:23 +0100 Subject: [PATCH] Added git expansion for checkout based on hg expansion --- Examples-(completion).md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Examples-(completion).md b/Examples-(completion).md index f3cc0ad..379e1fb 100644 --- a/Examples-(completion).md +++ b/Examples-(completion).md @@ -86,4 +86,27 @@ _fzf_complete_hg() { _fzf_complete_hg_post() { cut -f1 -d' ' } +``` + +### Complete `git co` (for example) + +You can use the same approach as above to complete any git command. In the example below, completion is triggered on `git co` (usual alias for `git checkout`): + +```sh +_fzf_complete_git() { + ARGS="$@" + local branches + branches=$(git branch -vv --all) + if [[ $ARGS == 'git co'* ]]; then + _fzf_complete "--reverse --multi" "$@" < <( + echo $branches + ) + else + eval "zle ${fzf_default_completion:-expand-or-complete}" + fi +} + +_fzf_complete_git_post() { + awk '{print $1}' +} ``` \ No newline at end of file