github.com/ishita82/trivy-gitaction@v0.0.0-20240206054925-e937cc05f8e3/docs/tutorials/shell/shell-completion.md (about) 1 # Enable shell completion 2 3 Below is example steps to enable shell completion feature for `trivy` cli: 4 5 ### 1. Know your current shell 6 7 ```bash 8 $ echo $SHELL 9 /bin/zsh # For this example it is zsh, but will be vary depend on your $SHELL, maybe /bin/bash or /bin/fish 10 ``` 11 12 ### 2. Run `completion` command to get sub-commands 13 14 ``` bash 15 $ trivy completion zsh -h 16 Generate the autocompletion script for the zsh shell. 17 18 If shell completion is not already enabled in your environment you will need 19 to enable it. You can execute the following once: 20 21 echo "autoload -U compinit; compinit" >> ~/.zshrc 22 23 To load completions in your current shell session: 24 25 source <(trivy completion zsh); compdef _trivy trivy 26 27 To load completions for every new session, execute once: 28 29 #### Linux: 30 31 trivy completion zsh > "${fpath[1]}/_trivy" 32 33 #### macOS: 34 35 trivy completion zsh > $(brew --prefix)/share/zsh/site-functions/_trivy 36 37 You will need to start a new shell for this setup to take effect. 38 ``` 39 40 ### 3. Run the sub-commands following the instruction 41 42 ```bash 43 echo "autoload -U compinit; compinit" >> ~/.zshrc 44 source <(trivy completion zsh); compdef _trivy trivy 45 trivy completion zsh > "${fpath[1]}/_trivy" 46 ``` 47 48 ### 4. Start a new shell and you can see the shell completion 49 50 ```bash 51 $ trivy [tab] 52 aws -- scan aws account 53 completion -- Generate the autocompletion script for the specified shell 54 config -- Scan config files for misconfigurations 55 filesystem -- Scan local filesystem 56 help -- Help about any command 57 image -- Scan a container image 58 kubernetes -- scan kubernetes cluster 59 module -- Manage modules 60 plugin -- Manage plugins 61 repository -- Scan a repository 62 rootfs -- Scan rootfs 63 sbom -- Scan SBOM for vulnerabilities 64 server -- Server mode 65 version -- Print the version 66 ```