-rw-r--r-- docker-completion.plugin.zsh
1 # Copyright 2020 Christian Fritz <mail at chr-fritz dot de> 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 # Adds the given file to the zsh variable fpath. 16 # Before adding it, it checks if the file exists. 17 __dockerCompletion_linkIfNeeded() { 18 local file=$1 19 local target="/usr/local/share/zsh/site-functions/$2" 20 if [[ -f "${file}" && ! -e "${target}" ]]; then 21 ln -s "${file}" "${target}" 22 fi 23 } 24 25 # Get the base path of the Docker for Mac installation. 26 # It assumes that the completions are relative to the real path of the docker command. 27 # This is the normal case for all Docker for Mac installations. 28 __dockerCompletion_basePath() { 29 docker_loc=$(which docker) 30 dirname $(dirname ${docker_loc:A}) 31 } 32 33 # Registers the docker completions from the Docker for Mac installation. 34 __dockerCompletion_registerCompletion(){ 35 basePath="$(__dockerCompletion_basePath)" 36 __dockerCompletion_linkIfNeeded "${basePath}/etc/docker.zsh-completion" "_docker" 37 __dockerCompletion_linkIfNeeded "${basePath}/etc/docker-machine.zsh-completion" "_docker-machine" 38 __dockerCompletion_linkIfNeeded "${basePath}/etc/docker-compose.zsh-completion" "_docker-compose" 39 } 40 41 __dockerCompletion_registerCompletion &>/dev/null 42