github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/data/completion/bash/snap (about) 1 # -*- sh -*- 2 # 3 # Copyright (C) 2016-2017 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 _complete_snap() { 18 # TODO: add support for sourcing this function from the core snap. 19 local cur prev words cword 20 _init_completion -n : || return 21 22 if [[ ${#words[@]} -le 2 ]]; then 23 # we're completing on the first word 24 COMPREPLY=($(GO_FLAGS_COMPLETION=1 "${words[@]}")) 25 return 0 26 fi 27 28 local command 29 if [[ ${words[1]} =~ ^- ]]; then 30 # global options take no args 31 return 0 32 fi 33 34 for w in "${words[@]:1}"; do 35 if [[ "$w" == "-h" || "$w" == "--help" ]]; then 36 # completing on help gets confusing 37 return 0 38 fi 39 done 40 41 command="${words[1]}" 42 43 # Only split on newlines 44 local IFS=$'\n' 45 46 # now we pass _just the bit that's being completed_ of the command 47 # to snap for it to figure it out. go-flags isn't smart enough to 48 # look at COMP_WORDS etc. itself. 49 if [ "$command" = "debug" ]; then 50 command="${words[2]}" 51 COMPREPLY=($(GO_FLAGS_COMPLETION=1 snap debug "$command" "$cur")) 52 elif [ "$command" = "routine" ]; then 53 command="${words[2]}" 54 COMPREPLY=($(GO_FLAGS_COMPLETION=1 snap routine "$command" "$cur")) 55 else 56 COMPREPLY=($(GO_FLAGS_COMPLETION=1 snap "$command" "$cur")) 57 fi 58 59 case $command in 60 install|info|sign-build) 61 _filedir "snap" 62 ;; 63 ack) 64 _filedir 65 ;; 66 try) 67 _filedir -d 68 ;; 69 connect|disconnect|interfaces) 70 # interface completions will only end in ':' when they all 71 # end in ':' (i.e. you either get offered snap names up to 72 # and including the ':', or you get offered the whole thing) 73 if [[ "$COMPREPLY" == *: ]]; then 74 compopt -o nospace 75 fi 76 esac 77 78 __ltrim_colon_completions "$cur" 79 80 return 0 81 } 82 83 complete -F _complete_snap snap