starship/docs/pt-BR/advanced-config/README.md
2020-09-30 16:26:13 -04:00

4.0 KiB

Advanced Configuration

Ainda que Starship seja um shell versátil, às vezes você precisará fazer algumas outras coisas além de editar o arquivo <code>starship.toml. Esta página detalha algumas das configurações mais avançadas usadas em starship.

::: warning

As configurações nesta seção estão sujeitas a alterações em futuras versões do Starship.

:::

Comandos personalizados de pre-prompt e pre-execution no Bash

O Bash não possui uma estrutura formal para os hooks preexec/precmd como a maioria dos outros shells. Por esse motivo, é difícil fornecer hooks totalmente customizáveis no bash. No entanto, Starship te oferece uma capacidade limitada de inserir suas próprias funções na processo de prompt-rendering:

  • To run a custom function right before the prompt is drawn, define a new function and then assign its name to starship_precmd_user_func. For example, to draw a rocket before the prompt, you would do
function blastoff(){
    echo "🚀"
}
starship_precmd_user_func="blastoff"
  • To run a custom function right before a command runs, you can use the DEBUG trap mechanism. However, you must trap the DEBUG signal before initializing Starship! Starship can preserve the value of the DEBUG trap, but if the trap is overwritten after starship starts up, some functionality will break.
function blastoff(){
    echo "🚀"
}
trap blastoff DEBUG     # Trap DEBUG *before* running starship
eval $(starship init bash)

Altera o título da janela

Some shell prompts will automatically change the window title for you (e.g. to reflect your working directory). Fish faz isso por padrão. Starship does not do this, but it's fairly straightforward to add this functionality to bash or zsh.

First, define a window title change function (identical in bash and zsh):

function set_win_title(){
    echo -ne "\033]0; YOUR_WINDOW_TITLE_HERE \007"
}

You can use variables to customize this title ($USER, $HOSTNAME, and $PWD are popular choices).

In bash, set this function to be the precmd starship function:

starship_precmd_user_func="set_win_title"

In zsh, add this to the precmd_functions array:

precmd_functions+=(set_win_title)

If you like the result, add these lines to your shell configuration file (~/.bashrc or ~/.zshrc) to make it permanent.

For example, if you want to display your current directory in your terminal tab title, add the following snippet to your ~/.bashrc or ~/.zshrc:

function set_win_title(){
    echo -ne "\033]0; $(basename $PWD) \007"
}
starship_precmd_user_func="set_win_title"

Estilo dos textos

Style strings are a list of words, separated by whitespace. The words are not case sensitive (i.e. bold and BoLd are considered the same string). Cada palavra pode ser uma das seguintes:

  • bold
  • underline
  • dimmed
  • bg:<color>
  • fg:<color>
  • <color>
  • none

where <color> is a color specifier (discussed below). fg:<color> and <color> currently do the same thing , though this may change in the future. The order of words in the string does not matter.

The none token overrides all other tokens in a string, so that e.g. fg:red none fg:blue will still create a string with no styling. It may become an error to use none in conjunction with other tokens in the future.

A color specifier can be one of the following:

  • One of the standard terminal colors: black, red, green, blue, yellow, purple, cyan, white. You can optionally prefix these with bright- to get the bright version (e.g. bright-white).
  • A # followed by a six-digit hexadecimal number. This specifies an RGB color hex code.
  • Um número entre 0-255. Este especifica um Código de Cor ANSI 8 bits.

If multiple colors are specified for foreground/background, the last one in the string will take priority.