github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/data/completion/zsh/_snap (about) 1 #compdef snap 2 # 3 # Copyright (C) 2020 Canonical Ltd 4 # 5 # This program is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License version 3 as 7 # published by the Free Software Foundation. 8 # 9 # This program is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 # group --style options and arguments separately, so that users can customize 18 # the presentation of available completion matches 19 _description options optexpl option 20 _description arguments argexpl argument 21 22 if [[ ${#words[@]} -ge 2 ]]; then 23 # keep track of the command for later reference 24 local command="${words[2]}" 25 fi 26 27 # get completion options with what we have so far 28 local matches=($(GO_FLAGS_COMPLETION=1 "${words[@]}")) 29 30 local match 31 # we don't have a command yet, try to complete one first 32 if [[ "$command" == "" ]]; then 33 for match in $matches; do compadd $optexpl[@] "$match"; done 34 return 0 35 fi 36 37 for match in $matches; do 38 case "$match" in 39 -*) compadd $optexpl[@] -- $match ;; 40 *) compadd $argexpl[@] $match ;; 41 esac 42 done 43 44 # some commands take files/directories too 45 case "$command" in 46 install) 47 # include *.snap files 48 _path_files -g "*.snap" 49 ;; 50 try) 51 # limit matches to directories 52 # TODO: only match directories with meta/snap.yaml inside 53 _path_files -/ 54 ;; 55 ack) 56 # there are no rules about assertion file names 57 _files 58 ;; 59 esac