Commit b56b3b6c authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add ZSH completion script for git-supertree

parent 5f71c243
Loading
Loading
Loading
Loading
+79 −0
Original line number Diff line number Diff line
#!zsh
# git-supertree completion script
#
# Completion script documentation:
# https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org

_git-supertree()
{
	local curcontext="$curcontext" state line
	typeset -A opt_args

	_arguments -C \
		':command:->command' \
		'*::options:->options'

	case $state in
		(command)

			local -a subcommands
			subcommands=(
				'init:Initialize a new git repo with support for the supertree layout .'
				'clone:Clone a new git repo with support for the supertree layout.'
				'convert:Convert a vanilla repo to a supertree layout.'
				'add:Add a worktree to the supertree.'
				'rm:Remove a worktree.'
			)
			_describe -t commands 'git supertree' subcommands
		;;

		(options)
			case $line[1] in

				(init)
					_arguments \
						'--branch[Initial branch and worktree name]:BRANCH:__git_supertree_branch_spec' \
						'::path:_directories' \
					;;

				(clone)
					_arguments \
						'--branch[Initial branch and worktree name]:BRANCH:__git_supertree_branch_spec' \
						':repository_url:' \
						'::path:_directories' \
					;;

				(convert)
					_arguments \
						"--master[Override the value of the base HEAD symbolic ref]:ref:($(__git_supertree_list_branches))" \
						'::path:_directories' \
					;;

				(add)
					_arguments \
						"--from[Override the value of the base HEAD symbolic ref]:ref:($(__git_supertree_list_branches))" \
						':BRANCH:__git_supertree_branch_spec' \
					;;

				(rm)
					_arguments \
						'--branch[Delete the branch as well as the working tree]' \
						':path:_directories' \
					;;
			esac
		;;
	esac
}


__git_supertree_list_branches()
{
	git branch -l | grep -v '*'
}

__git_supertree_branch_spec()
{
	_sep_parts "( $(__git_supertree_list_branches) )" : '*'
}

zstyle ':completion:*:*:git:*' user-commands supertree:'manage a collection of worktrees'