LinuxCommandLibrary

starship-init

Initialize Starship prompt in your shell

TLDR

Print the starship integration code for the specified shell

$ starship init [bash|elvish|fish|ion|powershell|tcsh|zsh]
copy

Append the starship integration code to ~/.bashrc
$ starship init [bash] >> [~/.bashrc]
copy

Append the starship integration code to ~/.zshrc
$ starship init [zsh] >> [~/.zshrc]
copy

Display help
$ starship init --help
copy

SYNOPSIS

starship init shell [options]

Examples:
eval "$(starship init bash)"
starship init zsh | source
starship init fish | source

PARAMETERS

shell
    The mandatory name of the shell for which to generate the initialization script. Common values include bash, zsh, fish, powershell, nu, elvish, tcsh, xonsh, and ion.

--print-full-init
    Prints the full initialization script, including all functions and variables, to standard output. This can be useful for debugging or complex shell setups.

-h, --help
    Displays help information about the starship init subcommand.

-V, --version
    Displays the version of the Starship prompt.

DESCRIPTION

starship init is a subcommand of the Starship prompt, a fast, customizable, and cross-shell prompt for the terminal. Its primary function is to generate the necessary initialization script for Starship to work correctly within a specified shell environment.

Instead of being a standalone executable that directly modifies your shell, starship init outputs the shell-specific code to standard output. Users typically pipe this output or source it directly within their shell configuration files (e.g., .bashrc, .zshrc, config.fish, config.nu).

This approach ensures that Starship integrates seamlessly and loads its prompt logic whenever a new shell session begins, providing a highly responsive and information-rich prompt experience. It supports a wide range of shells, making it a versatile tool for unifying prompt appearance across different environments. The generated script handles aspects like prompt rendering, command execution time, Git status, and other contextual information.

CAVEATS

The output of starship init must be sourced or evaluated by the shell, not just executed. Incorrect sourcing can lead to Starship not loading or causing shell errors.

Requires the starship executable to be installed and available in the system's PATH. Modifying shell configuration files (like .bashrc or .zshrc) requires care to avoid breaking existing shell functionality.

CONFIGURATION

Starship's appearance and behavior, including the modules displayed by the prompt, are extensively configurable via a starship.toml file. This configuration file is typically located at ~/.config/starship.toml.

It allows users to define custom prompt elements, colors, and conditional rendering based on contextual information such as Git status, Python virtual environments, Node.js versions, and more.

TYPICAL USAGE EXAMPLES

Here are common ways to integrate Starship into different shells using the init command:

  • For Bash: Add eval "$(starship init bash)" to ~/.bashrc
  • For Zsh: Add eval "$(starship init zsh)" to ~/.zshrc
  • For Fish: Add starship init fish | source to ~/.config/fish/config.fish
  • For Nushell: Add starship init nu | save starship.nu and then source starship.nu to your $nu.config-path

HISTORY

Starship emerged in the late 2010s as a modern, cross-shell prompt, quickly gaining popularity due to its speed (written in Rust), extensive configurability, and ease of installation. The starship init subcommand is central to its design philosophy, providing a standardized and elegant way for the prompt to integrate seamlessly with diverse shell environments.

Its development reflects a broader trend towards highly customizable and portable developer tooling, abstracting away the complexities of shell-specific prompt hooks and making Starship truly universal across various terminal setups.

SEE ALSO

starship(1), bash(1), zsh(1), fish(1), nu(1), eval(1), source(1)

Copied to clipboard