From 5c0189e9ca1cda9405cb2cfddf369945a39ace48 Mon Sep 17 00:00:00 2001 From: Benjamin Althues Date: Sun, 26 May 2013 18:20:39 +0200 Subject: Add zsh command completion function Add completion for gitto (sub)commands and arguments for users of the Z shell. --- zsh/_gitto | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 zsh/_gitto diff --git a/zsh/_gitto b/zsh/_gitto new file mode 100644 index 0000000..aefdb07 --- /dev/null +++ b/zsh/_gitto @@ -0,0 +1,73 @@ +#compdef gitto + +# gitto -- ZSH completion for gitto +# Copyright (C) 2013 Benjamin Althues + +# This file is part of gitto. + +# gitto is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# gitto is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with gitto. If not, see . + +local expl +local -a repository_locations +local -a _gitto_commands _gitto_config_commands _gitto_list_commands + +get_repository_locations() { + repository_locations=(${(f)"$(_call_program repository_locations \ + gitto list locations 2>/dev/null)"}) + _wanted repository_locations expl 'repository locations' \ + compadd -a repository_locations +} + +_gitto_commands=( + "add:register a new repository directory" + "check:check if a repository has been registered" + "config:show each repository's configuration" + "help:display help" + "list:list all repositories and their status" + "purge:remove all repositories that don't exist" + "remove:remove a repository directory" + "version:display version" +) +_gitto_config_commands=( + "global:show template configuration" + 'hooks:install configured hooks for repositories' + "update:merge template configuration with each repository's configuration" +) +_gitto_list_commands=( + "locations:list all registered repositories' locations" +) + +_arguments '*:: :->subcmds' && return 0 + +if (( CURRENT == 1 )); then + _describe -t commands "gitto command" _gitto_commands + return 0 +fi + +case "$words[1]" in + add|check) + _files -/ && return 0 ;; + config) + _describe -t commands "gitto config command" _gitto_config_commands + return 0 ;; + help|purge|version) + return 0 ;; + list) + _describe -t commands "gitto list command" _gitto_list_commands + return 0 ;; + remove) + get_repository_locations && return 0 +esac + +# vim: set ft=zsh et ts=2 sw=2 sts=2: -- cgit v1.2.3-54-g00ecf