Skip to content

Latest commit

 

History

History
459 lines (311 loc) · 8.39 KB

File metadata and controls

459 lines (311 loc) · 8.39 KB

dr self completion - Shell completion

Generate shell completion scripts for command auto-completion.

Quick start

For most users, setting up shell completion is a single command:

# Generate and install completion for your shell
# Bash (Linux)
dr self completion bash | sudo tee /etc/bash_completion.d/dr

# Zsh
dr self completion zsh > "${fpath[1]}/_dr"

# Fish
dr self completion fish > ~/.config/fish/completions/dr.fish

After installation, reload your shell to activate completions.

Note

First time? If you're new to the CLI, start with the Quick start for step-by-step setup instructions.

Synopsis

# Generate script for a shell (redirect to install)
dr self completion <shell>

# Interactive install or uninstall
dr self completion install [shell]
dr self completion uninstall [shell]

Supported shells: bash, zsh, fish, powershell.

Description

The self completion command generates shell completion scripts that enable auto-completion for the DataRobot CLI. You can either pass a shell name to output a script (then redirect to a file or pipe as needed), or use the install and uninstall subcommands for interactive setup. Completions provide command, subcommand, and flag suggestions when you press Tab.

Supported shells

  • bash—Bourne Again Shell.
  • zsh—Z Shell.
  • fish—Friendly Interactive Shell.
  • powershell—PowerShell.

Install and uninstall subcommands

For interactive setup without manually choosing paths:

  • dr self completion install [shell]—detects your shell (or use optional bash, zsh, fish, powershell), generates the script, and writes it to the appropriate location for your OS. Use --force to overwrite existing files.
  • dr self completion uninstall [shell]—removes previously installed completion files.

See the Shell completions guide for step-by-step instructions.

Usage

Bash

Linux:

# Install system-wide
dr self completion bash | sudo tee /etc/bash_completion.d/dr

# Reload shell
source ~/.bashrc

macOS:

# Install via Homebrew's bash-completion
brew install bash-completion@2
dr self completion bash > $(brew --prefix)/etc/bash_completion.d/dr

# Reload shell
source ~/.bash_profile

Temporary (current session only):

source <(dr self completion bash)

Zsh

Setup:

First, ensure completion is enabled:

# Add to ~/.zshrc if not present
autoload -U compinit
compinit

Installation:

# Option 1: User completions directory
mkdir -p ~/.zsh/completions
dr self completion zsh > ~/.zsh/completions/_dr
echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc

# Option 2: System directory
dr self completion zsh > "${fpath[1]}/_dr"

# Clear cache and reload
rm -f ~/.zcompdump
source ~/.zshrc

Temporary (current session only):

source <(dr self completion zsh)

Fish

# Install completion
dr self completion fish > ~/.config/fish/completions/dr.fish

# Reload Fish
source ~/.config/fish/config.fish

Temporary (current session only):

dr self completion fish | source

PowerShell

Persistent:

# Generate completion script
dr self completion powershell > dr.ps1

# Add to PowerShell profile
Add-Content $PROFILE ". C:\path\to\dr.ps1"

# Reload profile
. $PROFILE

Temporary (current session only):

dr self completion powershell | Out-String | Invoke-Expression

Examples

Generate completion script

# View the generated script
dr self completion bash

# Save to a file
dr self completion bash > dr-completion.bash

# Save for all shells
dr self completion bash > dr-completion.bash
dr self completion zsh > dr-completion.zsh
dr self completion fish > dr-completion.fish
dr self completion powershell > dr-completion.ps1

Install for multiple shells

If you use multiple shells:

# Bash
dr self completion bash > ~/.bash_completions/dr

# Zsh
dr self completion zsh > ~/.zsh/completions/_dr

# Fish
dr self completion fish > ~/.config/fish/completions/dr.fish

Update completions

After updating the CLI:

# Bash
dr self completion bash | sudo tee /etc/bash_completion.d/dr

# Zsh
dr self completion zsh > ~/.zsh/completions/_dr
rm -f ~/.zcompdump
exec zsh

# Fish
dr self completion fish > ~/.config/fish/completions/dr.fish

Completion behavior

Command completion

$ dr <Tab>
auth       completion dotenv     run        templates  version

$ dr auth <Tab>
check      login      logout     set-url

$ dr templates <Tab>
list       setup

Flag completion

$ dr run --<Tab>
--concurrency  --dir         --exit-code   --help
--list         --parallel    --silent      --watch
--yes

$ dr --<Tab>
--debug    --help     --verbose

Argument completion

Some commands support argument completion:

# Task names (when in a template directory)
$ dr run <Tab>
build  dev  deploy  lint  test

Troubleshooting

Completions not working

Bash:

  1. Verify bash-completion is installed:

    # macOS
    brew list bash-completion@2
    
    # Linux
    dpkg -l | grep bash-completion
  2. Check if completion script exists:

    ls -l /etc/bash_completion.d/dr
  3. Ensure .bashrc sources completions:

    grep bash_completion ~/.bashrc
  4. Reload shell:

    source ~/.bashrc

Zsh:

  1. Verify compinit is called:

    grep compinit ~/.zshrc
  2. Check fpath includes completion directory:

    echo $fpath
  3. Clear completion cache:

    rm -f ~/.zcompdump*
    compinit
  4. Reload shell:

    exec zsh

Fish:

  1. Check completion file:

    ls -l ~/.config/fish/completions/dr.fish
  2. Verify Fish recognizes it:

    complete -C dr
  3. Reload Fish:

    source ~/.config/fish/config.fish

PowerShell:

  1. Check execution policy:

    Get-ExecutionPolicy

    If restricted:

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
  2. Verify profile loads completion:

    cat $PROFILE
  3. Reload profile:

    . $PROFILE

Permission denied

Use user-level installation instead of system-wide:

# Bash - user level
mkdir -p ~/.bash_completions
dr self completion bash > ~/.bash_completions/dr
echo 'source ~/.bash_completions/dr' >> ~/.bashrc

# Zsh - user level
mkdir -p ~/.zsh/completions
dr self completion zsh > ~/.zsh/completions/_dr
echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc

Outdated completions

After updating the CLI, regenerate completions:

# Bash
dr self completion bash | sudo tee /etc/bash_completion.d/dr
source ~/.bashrc

# Zsh
dr self completion zsh > ~/.zsh/completions/_dr
rm -f ~/.zcompdump
exec zsh

# Fish
dr self completion fish > ~/.config/fish/completions/dr.fish

Completion features

Intelligent suggestions

Completions are context-aware:

# Only shows valid subcommands
dr auth <Tab>
# Shows: check login logout set-url (not other commands)

# Only shows valid flags
dr run --l<Tab>
# Shows: --list (not all flags)

Description support

In Fish and PowerShell, completions include descriptions:

$ dr templates <Tab>
list    (List available templates)
setup   (Interactive template setup wizard)

Dynamic completion

Some completions are generated dynamically:

# Task names from current Taskfile
dr run <Tab>

# Available shells
dr self completion <Tab>

Advanced configuration

Custom completion scripts

You can extend or modify generated completions:

# Generate base completion
dr self completion bash > ~/dr-completion-custom.bash

# Edit to add custom logic
vim ~/dr-completion-custom.bash

# Source your custom version
source ~/dr-completion-custom.bash

Completion performance

For faster completions, especially with dynamic suggestions:

# Cache template list
dr templates list > ~/.dr-templates-cache

# Use cached list in custom completion script

See also