I would like to get Bash completions for code
. How can that be done?
I tried using the search bar to see if this had already been asked (is:q [vscode] bash completion
, is:q [vscode] [bash-completion]
, is:q [vscode] zsh completion
, is:q [vscode] [zsh-completion]
) and googling "how to get bash completions for vscode
" and "how to get zsh completions for vscode
". I didn't see any existing Q&A on this topic (or maybe I just missed it?). I did find Add command line completion in zsh for the "code" command #47101, but that didn't really answer my quesiton.
VS Code provides Bash and Zsh completion files. The source code templates can be found in resources/completions/bash/code
and resources/completions/zsh/_code
.
Looking at the source code, at the time of this writing, this file is only made part of the installation for Linux builds, where the completions files is placed in usr/share/code/resources/completions/{bash,zsh}/code
(and also other directories).
I'm not sure if you actually have to do anything for Deb or RPM installations or if those are integrated automatically. But I definitely did have to take manual action for my Snap installation.
You can either source this file into one of your shell profile files (wherever they are, such as ~/.profile, ~/.bash_profile, etc.), or you can copy or symlink it to one of the locations that your shell looks for completion files. For example, for the Bash completion project, the /usr/share/bash-completion/bash_completion
script looks in a directory defined by local -a dirs=(${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions)
. See also Standard place for user defined bash_completion.d scripts?
For my Snap installation, I did ln -sT /snap/code/current/usr/share/code/resources/completions/bash/code ~/.local/share/bash-completion/completions/code
.