Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1b58ed1
Add completion install, uninstall, and status subcommands
simonfaltum Feb 23, 2026
489a10a
Fix uninstall newline corruption, CI failure, and PowerShell message
simonfaltum Feb 23, 2026
2f4b82f
Fix permission tests on Windows
simonfaltum Feb 23, 2026
e852ba0
Fix Windows shell detection fallback and fish uninstall ownership
simonfaltum Feb 23, 2026
6f62c98
Fix shell detection and fish completion ownership handling.
simonfaltum Feb 23, 2026
cff7a59
Merge branch 'main' into simonfaltum/completion-install-uninstall
simonfaltum Feb 23, 2026
0ba6417
Fix completion acceptance behavior across Windows and Unix.
simonfaltum Feb 23, 2026
b21f88c
Add confirmation prompt to completion install/uninstall
simonfaltum Feb 23, 2026
18e5e4d
Rename --yes to --auto-approve and add status hint
simonfaltum Feb 23, 2026
629fad7
Fix install no-op for fish foreign files and homebrew path in uninstall
simonfaltum Feb 23, 2026
ea2009f
Warn when zsh completions are installed but compinit is missing
simonfaltum Feb 24, 2026
5138948
Allow install to proceed when Homebrew completions exist
simonfaltum Feb 24, 2026
6f6690c
Merge branch 'main' into simonfaltum/completion-install-uninstall
simonfaltum Feb 24, 2026
369f96a
Address review comments: consolidate Status with Install, regex for b…
simonfaltum Feb 24, 2026
5028c89
Merge branch 'main' into simonfaltum/completion-install-uninstall
simonfaltum Feb 24, 2026
a5c69d2
Add NEXT_CHANGELOG.md entry for completion install/uninstall/status
simonfaltum Feb 24, 2026
5f8440e
Merge branch 'main' into simonfaltum/completion-install-uninstall
simonfaltum Feb 24, 2026
9ba71a0
Merge branch 'main' into simonfaltum/completion-install-uninstall
simonfaltum Feb 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Release v0.290.0

### CLI
* Add `completion install`, `uninstall`, and `status` subcommands ([#4581](https://github.com/databricks/cli/pull/4581))

### Internal

### Dependency updates
* Upgrade TF provider to 1.109.0 ([#4561](https://github.com/databricks/cli/pull/4561))
* Upgrade Go SDK to v0.110.0 ([#4552](https://github.com/databricks/cli/pull/4552))
Expand Down
5 changes: 5 additions & 0 deletions acceptance/cmd/completion/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions acceptance/cmd/completion/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

>>> [CLI] completion install --shell zsh --auto-approve
Databricks CLI completions installed for zsh.
Restart your shell or run 'source home/.zshrc' to activate.

Warning: zsh completions require the completion system to be initialized.
Add the following to your home/.zshrc:
autoload -U compinit && compinit

>>> [CLI] completion status --shell zsh
Shell: zsh
File: home/.zshrc
Status: installed

Warning: zsh completions require the completion system to be initialized.
Add the following to your home/.zshrc:
autoload -U compinit && compinit

>>> [CLI] completion install --shell zsh --auto-approve
Databricks CLI completions are already installed for zsh in home/.zshrc.

Warning: zsh completions require the completion system to be initialized.
Add the following to your home/.zshrc:
autoload -U compinit && compinit

>>> [CLI] completion uninstall --shell zsh --auto-approve
Databricks CLI completions removed for zsh from home/.zshrc.

>>> [CLI] completion status --shell zsh
Shell: zsh
File: home/.zshrc
Status: not installed
# bash completion V2 for databricks -*- shell-script -*-
#compdef databricks
# fish completion for databricks -*- shell-script -*-
# powershell completion for databricks -*- shell-script -*-
# bash completion V2 for databricks -*- shell-script -*-
31 changes: 31 additions & 0 deletions acceptance/cmd/completion/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
sethome "./home"

# Track the home path for stable output across platforms.
add_repl.py "$HOME" HOME

# Prevent Homebrew detection from affecting status output.
export HOMEBREW_PREFIX=/nonexistent

# Test install (use zsh to avoid OS-dependent bash RC file path)
trace $CLI completion install --shell zsh --auto-approve

# Test status shows installed
trace $CLI completion status --shell zsh

# Test idempotent install (--auto-approve is harmless when already installed)
trace $CLI completion install --shell zsh --auto-approve

# Test uninstall
trace $CLI completion uninstall --shell zsh --auto-approve

# Test status after uninstall
trace $CLI completion status --shell zsh

# Test shell subcommands produce output
$CLI completion bash 2>&1 | head -1
$CLI completion zsh 2>&1 | head -1
$CLI completion fish 2>&1 | head -1
$CLI completion powershell 2>&1 | head -1

# Test bash --no-descriptions
$CLI completion bash --no-descriptions 2>&1 | head -1
10 changes: 10 additions & 0 deletions acceptance/cmd/completion/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Ignore = [
"home",
]

Local = true
Cloud = false

# Completion tests don't involve bundles, skip the engine matrix.
[EnvMatrix]
DATABRICKS_BUNDLE_ENGINE = ["terraform"]
2 changes: 2 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/databricks/cli/cmd/auth"
"github.com/databricks/cli/cmd/bundle"
"github.com/databricks/cli/cmd/cache"
"github.com/databricks/cli/cmd/completion"
"github.com/databricks/cli/cmd/configure"
"github.com/databricks/cli/cmd/experimental"
"github.com/databricks/cli/cmd/fs"
Expand Down Expand Up @@ -94,6 +95,7 @@ func New(ctx context.Context) *cobra.Command {
// Add other subcommands.
cli.AddCommand(api.New())
cli.AddCommand(auth.New())
cli.AddCommand(completion.New())
cli.AddCommand(bundle.New())
cli.AddCommand(cache.New())
cli.AddCommand(experimental.New())
Expand Down
204 changes: 204 additions & 0 deletions cmd/completion/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
package completion

import (
"context"
"os"
"path/filepath"
"strings"

"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio"
libcompletion "github.com/databricks/cli/libs/completion"
"github.com/spf13/cobra"
)

// New returns the "completion" command with shell subcommands and
// install/uninstall/status subcommands. Providing a command named
// "completion" prevents Cobra's InitDefaultCompletionCmd from generating
// its default, so we replicate the shell subcommands here with runtime
// writer resolution to avoid the frozen-writer bug.
func New() *cobra.Command {
cmd := &cobra.Command{
Use: "completion",
Short: "Generate the autocompletion script for the specified shell",
Long: `Generate the autocompletion script for databricks for the specified shell.
See each sub-command's help for details on how to use the generated script.
`,
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: root.ReportUnknownSubcommand,
}

cmd.AddCommand(
newBashCmd(),
newZshCmd(),
newFishCmd(),
newPowershellCmd(),
newInstallCmd(),
newUninstallCmd(),
newStatusCmd(),
)

return cmd
}

func newBashCmd() *cobra.Command {
var noDesc bool
cmd := &cobra.Command{
Use: "bash",
Short: "Generate the autocompletion script for bash",
Long: `Generate the autocompletion script for the bash shell.

This script depends on the 'bash-completion' package.
If it is not installed already, you can install it via your OS's package manager.

To load completions in your current shell session:

source <(databricks completion bash)

To load completions for every new session, execute once:

#### Linux:

databricks completion bash > /etc/bash_completion.d/databricks

#### macOS:

databricks completion bash > $(brew --prefix)/etc/bash_completion.d/databricks

You will need to start a new shell for this setup to take effect.
`,
Args: cobra.NoArgs,
DisableFlagsInUseLine: true,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Root().GenBashCompletionV2(cmd.OutOrStdout(), !noDesc)
},
}
cmd.Flags().BoolVar(&noDesc, "no-descriptions", false, "disable completion descriptions")
return cmd
}

func newZshCmd() *cobra.Command {
var noDesc bool
cmd := &cobra.Command{
Use: "zsh",
Short: "Generate the autocompletion script for zsh",
Long: `Generate the autocompletion script for the zsh shell.

If shell completion is not already enabled in your environment you will need
to enable it. You can execute the following once:

echo "autoload -U compinit; compinit" >> ~/.zshrc

To load completions in your current shell session:

source <(databricks completion zsh)

To load completions for every new session, execute once:

#### Linux:

databricks completion zsh > "${fpath[1]}/_databricks"

#### macOS:

databricks completion zsh > $(brew --prefix)/share/zsh/site-functions/_databricks

You will need to start a new shell for this setup to take effect.
`,
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
if noDesc {
return cmd.Root().GenZshCompletionNoDesc(cmd.OutOrStdout())
}
return cmd.Root().GenZshCompletion(cmd.OutOrStdout())
},
}
cmd.Flags().BoolVar(&noDesc, "no-descriptions", false, "disable completion descriptions")
return cmd
}

func newFishCmd() *cobra.Command {
var noDesc bool
cmd := &cobra.Command{
Use: "fish",
Short: "Generate the autocompletion script for fish",
Long: `Generate the autocompletion script for the fish shell.

To load completions in your current shell session:

databricks completion fish | source

To load completions for every new session, execute once:

databricks completion fish > ~/.config/fish/completions/databricks.fish

You will need to start a new shell for this setup to take effect.
`,
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Root().GenFishCompletion(cmd.OutOrStdout(), !noDesc)
},
}
cmd.Flags().BoolVar(&noDesc, "no-descriptions", false, "disable completion descriptions")
return cmd
}

func newPowershellCmd() *cobra.Command {
var noDesc bool
cmd := &cobra.Command{
Use: "powershell",
Short: "Generate the autocompletion script for powershell",
Long: `Generate the autocompletion script for powershell.

To load completions in your current shell session:

databricks completion powershell | Out-String | Invoke-Expression

To load completions for every new session, add the output of the above command
to your powershell profile.
`,
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
if noDesc {
return cmd.Root().GenPowerShellCompletion(cmd.OutOrStdout())
}
return cmd.Root().GenPowerShellCompletionWithDesc(cmd.OutOrStdout())
},
}
cmd.Flags().BoolVar(&noDesc, "no-descriptions", false, "disable completion descriptions")
return cmd
}

// warnIfCompinitMissing prints a warning when zsh completions are present but
// the user's .zshrc does not call compinit. Without compinit, neither our eval
// shim nor Homebrew's _databricks file will be loaded.
func warnIfCompinitMissing(ctx context.Context, shell libcompletion.Shell, home string) {
if shell != libcompletion.Zsh {
return
}
rcPath := libcompletion.TargetFilePath(shell, home)
content, err := os.ReadFile(rcPath)
if err != nil {
return
}
if strings.Contains(string(content), "compinit") {
return
}
cmdio.LogString(ctx, "")
cmdio.LogString(ctx, "Warning: zsh completions require the completion system to be initialized.")
cmdio.LogString(ctx, "Add the following to your "+filepath.ToSlash(rcPath)+":")
cmdio.LogString(ctx, " autoload -U compinit && compinit")
}

// addShellFlag registers the --shell flag and its completion function on cmd.
func addShellFlag(cmd *cobra.Command, target *string) {
cmd.Flags().StringVar(target, "shell", "", "Shell type: bash, zsh, fish, powershell, powershell5")
cmd.RegisterFlagCompletionFunc("shell", func(cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective) {
return []cobra.Completion{"bash", "zsh", "fish", "powershell", "powershell5"}, cobra.ShellCompDirectiveNoFileComp
})
}
Loading