DEV Community

Higor Morais
Higor Morais

Posted on

Guia de Configuração: Zsh, Oh My Zsh e Atuin

Aqui está um tutorial completo sobre como instalar o Oh My Zsh (junto com os plugins mais populares) e configurar o Atuin para o histórico do shell.

No final deste guia, você encontrará um Makefile que automatiza essas instalações para que você possa replicar facilmente essa configuração em qualquer sistema baseado em Unix (Linux ou macOS).


1. Pré-requisitos

Certifique-se de ter o zsh, curl e git instalados no seu sistema.

No Ubuntu/Debian:

sudo apt update
sudo apt install zsh curl git
Enter fullscreen mode Exit fullscreen mode

No macOS (via Homebrew):

brew install zsh curl git
Enter fullscreen mode Exit fullscreen mode

Defina o Zsh como seu shell padrão:

chsh -s $(which zsh)
Enter fullscreen mode Exit fullscreen mode

2. Instalação do Oh My Zsh

Execute o script oficial de instalação:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Enter fullscreen mode Exit fullscreen mode

3. Instalando Plugins do Zsh

(Nota: Como não consegui ler automaticamente seus plugins específicos do .zshrc, incluí os dois plugins da comunidade mais essenciais e populares. Você pode adicionar outros facilmente à lista!)

1. zsh-autosuggestions (Sugere comandos enquanto você digita com base no histórico)

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Enter fullscreen mode Exit fullscreen mode

2. zsh-syntax-highlighting (Destaca a sintaxe dos comandos enquanto são digitados)

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Enter fullscreen mode Exit fullscreen mode

Configuração:
Abra seu arquivo ~/.zshrc e atualize o array plugins para incluí-los (junto com o git), assim:

plugins=(
    git
    zsh-autosuggestions
    zsh-syntax-highlighting
    # Adicione seus outros plugins aqui!
)
Enter fullscreen mode Exit fullscreen mode

Em seguida, recarregue seu shell: source ~/.zshrc


4. Instalação e Configuração do Atuin

O Atuin substitui seu histórico de shell existente por um banco de dados SQLite, permitindo sincronização criptografada e recursos incríveis de pesquisa.

Instalação:

curl --proto '=https' --tlsv1.2 -LsSf https://setup.atuin.sh | sh
Enter fullscreen mode Exit fullscreen mode

Configuração:
O Atuin deve se adicionar automaticamente ao seu ~/.zshrc. Se não o fizer, adicione esta linha no FINAL do seu ~/.zshrc:

eval "$(atuin init zsh)"
Enter fullscreen mode Exit fullscreen mode

Sincronização e Configuração de Conta (Opcional, mas recomendado):
Se você quiser fazer backup e sincronizar seu histórico entre computadores:

# Registre uma conta
atuin register -u <USUARIO> -e <EMAIL>

# Ou se você já tem uma conta, faça login:
atuin login -u <USUARIO>

# Importe seu histórico existente
atuin import auto

# Sincronize
atuin sync
Enter fullscreen mode Exit fullscreen mode

5. Configuração Automatizada via Makefile

Para facilitar as coisas em qualquer sistema baseado em Unix, crie um arquivo chamado Makefile e cole o conteúdo a seguir.

Este Makefile verifica as dependências, instala o Oh My Zsh, clona os plugins, instala o Atuin e fornece um comando para atualizar automaticamente o seu .zshrc.

# Makefile para configuração do Zsh, Oh My Zsh, Plugins e Atuin

.PHONY: all check-deps install-zsh install-oh-my-zsh install-plugins install-atuin configure-zshrc

all: check-deps install-oh-my-zsh install-plugins install-atuin configure-zshrc
    @echo "======================================================="
    @echo "Instalação concluída! Por favor, reinicie seu terminal ou execute:"
    @echo "exec zsh"
    @echo "======================================================="

check-deps:
    @echo "Verificando dependências..."
    @command -v git >/dev/null 2>&1 || { echo >&2 "git é necessário, mas não está instalado. Abortando."; exit 1; }
    @command -v curl >/dev/null 2>&1 || { echo >&2 "curl é necessário, mas não está instalado. Abortando."; exit 1; }
    @command -v zsh >/dev/null 2>&1 || { echo >&2 "zsh é necessário. Por favor, instale o Zsh primeiro."; exit 1; }

install-oh-my-zsh:
    @echo "Instalando Oh My Zsh..."
    @if [ ! -d "$$HOME/.oh-my-zsh" ]; then \
        RUNZSH=no sh -c "$$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"; \
    else \
        echo "Oh My Zsh já está instalado."; \
    fi

install-plugins:
    @echo "Instalando Plugins do Zsh..."
    @if [ ! -d "$${ZSH_CUSTOM:-$$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" ]; then \
        git clone https://github.com/zsh-users/zsh-autosuggestions "$${ZSH_CUSTOM:-$$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions"; \
    else \
        echo "zsh-autosuggestions já está instalado."; \
    fi
    @if [ ! -d "$${ZSH_CUSTOM:-$$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting" ]; then \
        git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$${ZSH_CUSTOM:-$$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting"; \
    else \
        echo "zsh-syntax-highlighting já está instalado."; \
    fi

install-atuin:
    @echo "Instalando o Atuin..."
    @if ! command -v atuin >/dev/null 2>&1; then \
        curl --proto '=https' --tlsv1.2 -LsSf https://setup.atuin.sh | sh; \
    else \
        echo "Atuin já está instalado."; \
    fi

configure-zshrc:
    @echo "Configurando ~/.zshrc..."
    @if grep -q "plugins=(git)" $$HOME/.zshrc; then \
        sed -i.bak 's/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/' $$HOME/.zshrc; \
        echo "Plugins atualizados no ~/.zshrc"; \
    fi
    @if ! grep -q "atuin init zsh" $$HOME/.zshrc; then \
        echo 'eval "$$(atuin init zsh)"' >> $$HOME/.zshrc; \
        echo "Inicialização do Atuin adicionada ao ~/.zshrc"; \
    fi
Enter fullscreen mode Exit fullscreen mode

Como usar o Makefile:

  1. Salve o bloco de código acima como Makefile
  2. Abra o seu terminal no diretório onde você o salvou.
  3. Execute o comando: make ou make all

Ele configurará tudo perfeitamente para você!

Top comments (0)