{"id":13676324,"url":"https://github.com/MartinSimango/kubectl-plugin_completion","last_synced_at":"2025-04-29T06:31:43.648Z","repository":{"id":144417098,"uuid":"481583469","full_name":"MartinSimango/kubectl-plugin_completion","owner":"MartinSimango","description":"A kubectl plugin for allowing kubectl plugin completions","archived":false,"fork":false,"pushed_at":"2022-06-07T10:43:12.000Z","size":750,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-11T18:41:02.184Z","etag":null,"topics":["autocompletion","bash","kubectl","kubectl-plugin","terminal","zsh"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MartinSimango.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-04-14T11:45:35.000Z","updated_at":"2024-06-22T13:17:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"91cdd6e1-0755-4c36-8523-bf994a75770b","html_url":"https://github.com/MartinSimango/kubectl-plugin_completion","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinSimango%2Fkubectl-plugin_completion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinSimango%2Fkubectl-plugin_completion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinSimango%2Fkubectl-plugin_completion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinSimango%2Fkubectl-plugin_completion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MartinSimango","download_url":"https://codeload.github.com/MartinSimango/kubectl-plugin_completion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251450656,"owners_count":21591407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autocompletion","bash","kubectl","kubectl-plugin","terminal","zsh"],"created_at":"2024-08-02T13:00:22.841Z","updated_at":"2025-04-29T06:31:38.635Z","avatar_url":"https://github.com/MartinSimango.png","language":"Go","readme":"# kubectl-plugin_completion\n\n\u003e :warning: **Notice**\n\u003e * This has been tested on for kubectl v1.23 and has not been tested on the kubectl v1.24.\n\u003e * Not all kubectl plugins have been tested. You can find a listed of tested plugins at [here](https://github.com/MartinSimango/kubectl-plugin_completion/blob/main/tested-plugins.txt). Please note if a plugin hasn't been tested\n\u003e it might cause unwanted errors such as your shell hanging.\n\u003e * Plugin only supports zsh and bash shells (for now).\n\n\nAuto completion saves a lot of time when typing in commands. The kubectl tool has a way to allow for completion for it's sub-commands,\nhowever it doesn't not accomodate for when these sub-commands are plugin commands. This repo contains the code for a kubectl plugin that generates scripts for extending the kubectl tool in order to accomodate for completions for kubectl plugin sub-commands.\n\n## Sections\n* [Install plugin](https://github.com/MartinSimango/kubectl-plugin_completion#install-plugin)\n* [How it works](https://github.com/MartinSimango/kubectl-plugin_completion#how-it-works)\n* [How to use](https://github.com/MartinSimango/kubectl-plugin_completion#how-to-use)\n* [Example](https://github.com/MartinSimango/kubectl-plugin_completion#example)\n\n\n## Install plugin\n\nPlugin can be installed in 3 ways:\n\n1. Via krew\n ```sh \n$ kubectl krew install --manifest-url https://github.com/MartinSimango/kubectl-plugin_completion/releases/download/v0.1.2/plugin_completion.yaml\n``` \n2. Zip file containing binary can be downloaded on the [release page](https://github.com/MartinSimango/kubectl-plugin_completion/releases)\n\n3. Manually by cloning the repo and running make install - (This requires you having go installed)\n\n\n## How it works\n\nThe plugin works by reading config files for specfic shells (so far only bash and zsh). These config files in a folder located at `$HOME/.kube/plugin-completion-config` and are named `$SHELL_NAME.yaml`. So for example the zsh config file will be located at `$HOME/.kube/plugin-completion-config/zsh.yaml`. \n\nThe config files contain information about the available kubectl plugins along with some additional information such as the plugin's description and the plugin's completion function name. Below is an example of what a config file for a zsh terminal will look like:\n\n```yaml\nshell: zsh\nshellLocation: /bin/zsh\nplugins:\n- name: access_matrix\n  completionFunctionName: \"\"\n  description: 'Show an RBAC access matrix for server resources '\n  supportsCobraCompletion: false\n- name: accurate\n  completionFunctionName: _accurate\n  description: 'Manage Accurate, a multi-tenancy controller '\n  supportsCobraCompletion: true\n- name: allctx\n  completionFunctionName: \"\"\n  description: 'Run commands on contexts in your kubeconfig '\n  supportsCobraCompletion: false\n- name: plugin_completion\n  completionFunctionName: _plugin_completion\n  description: A kubectl plugin for allowing shell completions for kubectl plugins\n  supportsCobraCompletion: true\nkubectlOverridePlugins:\n- allctx\n```\n\nThe above file can be generated by running: \n``` sh\n$ kubectl plugin_completion config generate \n```\nThis will generate config files for all supported shells (zsh and bash). For plugins that were created using [cobra](https://github.com/spf13/cobra) and have that have a cobra completion command the `completionFunctionName` field will automatically be field in. The description for each plugin will default to: \"A kubectl plugin called $plugin_name\" if the plugin is not found in the krew repository. \n\nIf a plugin was not created by using [cobra](https://github.com/spf13/cobra) or if the plugin was created using cobra but does not have a completion subcommand, it will be up to you to manually edit the config file and provide the name of the plugin's completion function name. This can also be done by running the `kubectl plugin_completion config edit` command as shown below:\n\n```sh\n$ kubectl plugin_completion config edit zsh --plugin-name=plugin_name --completion-function=\"_completion_function_name\"\n```\n\nPlugins who's completion script override the default kubectl completion function such as the allctx plugin can be added to the kubectlOverridePlugins array. Thus typing `kubectl allctx \u003cTAB\u003e\u003cTAB\u003e` will still give completions for the kubectl command.\n\nThe plugin_completion uses config files to generate completions specific shells in order to allow for completions for kubectl plugins. The generated completion scripts overwrite the behaviour of the completion function for the kubectl tool and extend it to allow for kubectl plugin completions.\n\n## How to use\n\nTo start of you will need to generate your shell plugin config files. This can be done by running the below command:\n``` sh\n$ kubectl plugin_completion config generate \n```\n\nOnce the config files are generated you can source the plugin completion script by running:\n\n```sh\n$ source \u003c(kubectl plugin_completion plugin-completion $SHELL)\n```\n\nwhere `$SHELL` is the shell you want to generate the completion script for. \n\nTo make the changes permanent you can add  `source \u003c(kubectl plugin_completion plugin-completion zsh)` to your `~/.zshrc` file or `source \u003c(kubectl plugin_completion plugin-completion bash)` to your `~/.bashrc (or ~/.bash_profile)` file. \n\nPlease note if you change the config files for a shell you will need to rerun the `source \u003c(kubectl plugin_completion plugin-completion $SHELL)` command as the plugin completion script is generated from using information from the config files. \n\nOnce the above is done completions for your plugins should work as displayed in the below Example section.\n\n\n## Example\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/MartinSimango/kubectl-plugin_completion/blob/main/kub-plugin.gif\" style=\"width:600px;height=1000px\"/\u003e\n\u003c/p\u003e\n\n\n","funding_links":[],"categories":["Completions","Go"],"sub_categories":["ZSH on Windows"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMartinSimango%2Fkubectl-plugin_completion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMartinSimango%2Fkubectl-plugin_completion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMartinSimango%2Fkubectl-plugin_completion/lists"}