# init

## `atuin init <shell>`

Prints the shell plugin for the given shell. Evaluating its output is what
installs Atuin's hooks and key bindings into your session, so this command
belongs in your shell's startup file rather than being run by hand.

```shell
atuin init zsh
```

`atuin setup` adds the `atuin init` line to the startup files of zsh, bash, fish
and PowerShell. To add it without the setup screen, pass `--only` and name the
shells with `--shells`:

```shell
atuin setup --only --shell-history --shells zsh,bash,fish,powershell
```

| Shell      | Startup file that setup writes to                                                                                               |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------- |
| zsh        | `$ZDOTDIR/.zshrc`, or `~/.zshrc` when `ZDOTDIR` isn't set                                                                       |
| bash       | `~/.bashrc`                                                                                                                     |
| fish       | `~/.config/fish/config.fish`, inside an `if status is-interactive` block                                                        |
| PowerShell | `~/.config/powershell/Microsoft.PowerShell_profile.ps1`, or on Windows, the profiles of both PowerShell 7 and Windows PowerShell |

Setup leaves a startup file that already runs `atuin init` as it is.
`atuin setup --only --no-shell-history` takes out the lines that setup wrote.

For Nushell and xonsh, add the line to your startup file yourself. See
[installation](/getting-started/installation/#installing-the-shell-plugin) for the
exact line to add for your shell — the syntax differs between shells.

Supported shells: `zsh`, `bash`, `fish`, `nu`, `xonsh`, `powershell`. See
[Supported platforms](/help/supported-platforms/) for what each tier means.

## What it sets up

- **Hooks** that record each command, its exit code, and its duration. See
  [Shell Integration](/guide/shell-integration/).
- **Key bindings** for <kbd>Ctrl</kbd>+<kbd>R</kbd> and the <kbd>↑</kbd> arrow.
- **Widgets** for `atuin resume` (zsh, bash and fish), unbound unless you ask
  for them: see [Binding `atuin resume`](#binding-atuin-resume).

## Flags

| Flag                 | Description                                                                                          |
| -------------------- | ---------------------------------------------------------------------------------------------------- |
| `--disable-up-arrow` | Don't bind the <kbd>↑</kbd> arrow key                                                                |
| `--disable-ctrl-r`   | Don't bind <kbd>Ctrl</kbd>+<kbd>R</kbd>                                                              |
| `--bind-ai-resume`   | Bind <kbd>Ctrl</kbd>+<kbd>bracket-right</kbd> to `atuin resume` (zsh, bash and fish; off by default) |

For example, to keep <kbd>Ctrl</kbd>+<kbd>R</kbd> but leave the up arrow alone:

```shell
eval "$(atuin init zsh --disable-up-arrow)"
```

`atuin setup --only --no-up-arrow` and `atuin setup --only --no-ctrl-r` turn
the same keys off through the
[`bind_up_arrow` and `bind_ctrl_r`](/reference/config/general/#bind_up_arrow)
settings, and leave the `atuin init` line as it is.

## Binding `atuin resume`

`atuin init` defines widgets that open the [`atuin resume`](/ai/threads/)
picker at the prompt and put the command it picks into your shell, but binds no
key to them by default. To bind <kbd>Ctrl</kbd>+<kbd>bracket-right</kbd> in the emacs, vi-insert and
vi-command keymaps, pass `--bind-ai-resume`:

```shell
eval "$(atuin init zsh --bind-ai-resume)"
```

:::note[<kbd>Ctrl</kbd>+<kbd>bracket-right</kbd> replaces a shell binding]

<kbd>Ctrl</kbd>+<kbd>bracket-right</kbd> is zsh's `vi-find-next-char` (emacs keymap) and bash's
`character-search`: jump to the next occurrence of the character you type next. `--bind-ai-resume`
replaces it. To keep it, bind the widget to another key yourself. :::

To bind a key of your choice instead, add it after the `atuin init` line:

```shell
eval "$(atuin init zsh)"
bindkey -M emacs '^x^r' atuin-ai-resume
bindkey -M viins '^x^r' atuin-ai-resume-viins
bindkey -M vicmd '^x^r' atuin-ai-resume-vicmd
```

```shell
eval "$(atuin init bash)"
atuin-bind -m emacs      '\C-x\C-r' atuin-ai-resume-emacs
atuin-bind -m vi-insert  '\C-x\C-r' atuin-ai-resume-viins
atuin-bind -m vi-command '\C-x\C-r' atuin-ai-resume-vicmd
```

`atuin-bind` is the helper `atuin init bash` defines (see
[Key Binding](/configuration/key-binding/)); it also works under ble.sh.

```fish
atuin init fish | source
bind ctrl-x,ctrl-r _atuin_ai_resume
bind -M insert ctrl-x,ctrl-r _atuin_ai_resume
```

(Fish 3.x spells the key `\cx\cr`.)

## Environment variables

| Variable                   | Effect                                                                                                     |
| -------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `ATUIN_NOBIND`             | If set to any value, binds no keys at all. Equivalent to passing every `--disable-*` flag.                 |
| `ATUIN_NO_BUILTIN_PREEXEC` | Bash only. Stops `atuin init bash` from automatically loading its bundled bash-preexec (Atuin >= 18.18.0). |

Binding no keys is useful when you want to choose the bindings yourself:

```shell
export ATUIN_NOBIND="true"
eval "$(atuin init zsh)"

bindkey '^r' atuin-search
```

See [Key Binding](/configuration/key-binding/) for the widget and function
names each shell exposes, and
[Advanced Key Binding](/configuration/advanced-key-binding/) for customizing
the keys _inside_ the TUI.