From 001e4f345bb8e267844f0eb7dafcbd824a3832f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Thu, 29 Nov 2018 13:21:09 +0100 Subject: git: Add gitbcheckout --- zsh-completion/_gitbcheckout | 16 ++++++++++++++++ zsh-completion/_gitbmerge | 20 +++++++------------- 2 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 zsh-completion/_gitbcheckout (limited to 'zsh-completion') diff --git a/zsh-completion/_gitbcheckout b/zsh-completion/_gitbcheckout new file mode 100644 index 0000000..050457d --- /dev/null +++ b/zsh-completion/_gitbcheckout @@ -0,0 +1,16 @@ +#compdef gitbmerge +#autoload + +_gitbcheckout() { + ((CURRENT > 2)) && return # Complete only single branch + local gdir branch + gdir="$(git rev-parse --git-common-dir 2>/dev/null)" || return + local branches=() + while read -r branch; do + branches+=("$branch") + done < <(find "$gdir/refs/heads" "$gdir/refs/remotes" -mindepth 1 -printf '%P\n') + _describe -t branches 'gitbcheckout' branches +} + +_gitbcheckout +# vim: ft=zsh diff --git a/zsh-completion/_gitbmerge b/zsh-completion/_gitbmerge index 733dbfb..0b598a0 100644 --- a/zsh-completion/_gitbmerge +++ b/zsh-completion/_gitbmerge @@ -2,20 +2,14 @@ #autoload _gitbmerge() { - (( CURRENT > 2)) && return # Complete only single dependency - local GDIR="$(pwd)" - while [ ! -d "$GDIR/.git" ]; do - [ -z "$GDIR" ] && return - GDIR="${GDIR%/*}" - done - GDIR="$GDIR/.git" - [ -f "$GDIR" ] && GDIR="$(cat "$GDIR")" # This just points to some other directory - [ -d "$GDIR/refs/heads" ] || return # No completion if there is no local branch + ((CURRENT > 2)) && return # Complete only single branch + local gdir branch + gdir="$(git rev-parse --git-common-dir 2>/dev/null)" || return local branches=() - for B in "$GDIR"/refs/heads/*; do - # TODO skip branch on HEAD - branches+=("${B#$GDIR/refs/heads/}") - done + # TODO ignore current HEAD (merging HEAD to HEAD does not makes sense) + while read -r branch; do + branches+=("$branch") + done < <(find "$gdir/refs/heads" -mindepth 1 -printf '%P\n') _describe -t branches 'gitbmerge' branches } -- cgit v1.2.3