# uip completion

> Install, print, or remove shell tab completion for UiPath CLI on bash, zsh, fish, and PowerShell.

`uip completion` installs, prints, or removes shell tab completion for `uip`. It supports **bash**, **zsh**, **fish**, and **pwsh** (PowerShell). Interactive when invoked without an explicit shell argument in a TTY; dumps the completion script to stdout when given a shell argument or when stdout is not a TTY.

For the full walkthrough including per-shell rc-file examples and proxy notes, see [Installing UiPath CLI — Enable shell completion](./installing-uipath-cli.md#enable-shell-completion).

## Synopsis

```
uip completion [shell] [--print] [--uninstall]
```

All flags honor the [global options](./global-options.md) (`--output`, `--output-filter`, `--log-level`, `--log-file`). Exit codes follow the [standard contract](./exit-codes.md); cancelling an interactive confirm prompt exits with `130` (user cancel).

## Arguments

- `[shell]` *(optional)* — One of `bash`, `zsh`, `fish`, `pwsh` (alias: `powershell`). When omitted, the shell is auto-detected from `$SHELL` / `$PSModulePath` / the platform.

## Options

- `--print` — Print the target rc-file path and the block that would be written, without modifying the filesystem. Useful for previewing what `uip completion` would do.
- `--uninstall` — Remove the managed completion block (or, for fish, the generated completion file) instead of installing. Idempotent — a no-op if the block is already absent.

## Behavior

The command follows a simple three-branch rule:

1. **Interactive install** (no shell arg, stdout is a TTY) — auto-detects the shell, prints the target rc file, and prompts for confirmation before writing. Cancel with Ctrl-C to exit `130`.
2. **Script dump** (explicit shell arg, *or* stdout is not a TTY) — writes the generated completion script to stdout. Pipe it into your rc file or source it directly:

   ```bash
   uip completion zsh >> ~/.zshrc
   uip completion bash >> ~/.bashrc
   uip completion fish > ~/.config/fish/completions/uip.fish
   uip completion pwsh >> $PROFILE
   ```
3. **Uninstall** (`--uninstall`) — removes the managed block, regardless of TTY state.

## Examples

```bash
# Interactive install — auto-detect shell, prompt, write rc file
uip completion

# Preview without touching the filesystem
uip completion --print

# Dump the zsh script to a specific rc file
uip completion zsh >> ~/.zshrc

# Dump the PowerShell script to your profile
uip completion pwsh >> $PROFILE

# Remove the managed completion block
uip completion --uninstall
```

## Data shape (--output json)

On successful install:

```json
{
  "Code": "CompletionInstalled",
  "Data": {
    "shell": "zsh",
    "path": "/Users/alice/.zshrc",
    "action": "appended",
    "notes": [
      "Dynamic flag-value completion (e.g. --package-name <TAB>) requires `jq` on PATH; without it, those candidates are suppressed."
    ]
  }
}
```

On `--print`:

```json
{
  "Code": "CompletionPrint",
  "Data": {
    "shell": "zsh",
    "path": "/Users/alice/.zshrc",
    "mode": "block",
    "content": "# >>> uip completion >>>\n…generated script…\n# <<< uip completion <<<"
  }
}
```

On `--uninstall`:

```json
{
  "Code": "CompletionUninstalled",
  "Data": {
    "shell": "zsh",
    "path": "/Users/alice/.zshrc",
    "action": "removed"
  }
}
```

## Failure modes

- **Unsupported shell** — `Failure` with `Message: "Unsupported shell: <name>"`, instructions to use one of `bash`, `zsh`, `fish`, `pwsh`.
- **Shell-special characters in a command name** — `Failure` from the zsh / fish generator; rename the offending command or open an issue.
- **No write access to the rc file** — `Failure` with instructions to check permissions on the target path.
- **User cancels the confirm prompt** — exits `130` (no envelope).

## Dynamic flag-value completion

Static completion (subcommand names, option names) works on all four shells. **Dynamic flag-value completion** — for example, `uip or packages upload --package-name <TAB>` suggesting live package names — is currently **zsh-only** and requires `jq` on `PATH`. Without `jq`, dynamic candidates are suppressed silently; the install step emits a note in the `notes[]` array when this applies.

## Static snapshot: re-run after every upgrade

The generated completion script is a **static snapshot** of the subcommand names and option names known when `uip completion` was run. It is not regenerated at shell startup. After any of the following, re-run `uip completion` so newly added verbs and flags appear in tab completion:

- `npm install -g @uipath/cli@<new-version>` — the host bumped, new global flags or top-level commands may exist.
- `uip tools install <new-tool>` — a tool you didn't have is now installed; its alias and verbs are not in the script yet.
- `uip tools update` — installed tools moved to a new MINOR; new verbs or flags may have been added.

```bash
uip completion              # interactive — refreshes the existing block
uip completion zsh >> ~/.zshrc   # or pipe into the rc file directly
```

Without a refresh, the new verbs still work on the command line — they just won't be suggested by `<TAB>`. Dynamic flag-value completion (the zsh-only case above) is the one piece that resolves at runtime; everything else needs the refresh.

## Related

- [Installing UiPath CLI — Enable shell completion](./installing-uipath-cli.md#enable-shell-completion) — per-shell setup walkthrough and troubleshooting.
- [Troubleshooting — Tab completion doesn't complete](./troubleshooting.md#tab-completion-doesnt-complete) — common install-time issues.
- [Scripting patterns — Suppressing interactive prompts](./scripting-patterns.md#suppressing-interactive-prompts) — avoiding the confirm prompt in CI.

## See also

- [uip tools](./uip-tools.md) — `uip completion` reflects the installed tools' subcommands; re-run after `uip tools install` if you want completion for newly-installed commands.
- [Global options](./global-options.md) — `--output`, `--output-filter`, `--log-level`, `--log-file`.
- [Exit codes](./exit-codes.md) — the standard contract plus `130` for user cancellation.
