Configurar ZSH no terminal com ssh-agent e auto-suggestions

Este tutorial detalhado guia você pela instalação e configuração do Oh My Zsh no Ubuntu ou derivados, com o tema agnoster, fontes Nerd Fonts para ícones, plugins úteis (git, ssh-agent, zsh-autosuggestions) e configuração de SSH para o GitHub.

📦 Pré-requisitos

Verifique se você possui:

  • ✅ Sistema: Ubuntu ou derivados (ex: Pop!_OS, Linux Mint)
  • ✅ Acesso sudo
  • ✅ Git instalado
  • ✅ Conexão com a internet

Verifique o Git:

git --version

Instale caso necessário:

sudo apt update
sudo apt install git -y

Instale também wget e unzip:

sudo apt install wget unzip -y

🐚 Instalando o Zsh

Atualize os pacotes:

sudo apt update

Instale o Zsh:

sudo apt install zsh

Verifique a versão:

zsh --version

Esperado: zsh 5.8 ou superior.

💾 Instalando o Oh My Zsh

Instale o Oh My Zsh:

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

Caso necessário, defina o Zsh como shell padrão:

chsh -s $(which zsh)

Feche e reabra o terminal.

🎨 Configurando o Tema Agnoster

Edite o arquivo .zshrc:

nano ~/.zshrc

Altere a linha do tema:

ZSH_THEME="agnoster"

Salve com:

  • Ctrl + O (salvar)
  • Enter (confirmar)
  • Ctrl + X (sair)

Aplique as alterações:

source ~/.zshrc

🔤 Instalando a Nerd Font

Crie um diretório de fontes:

mkdir -p ~/.local/share/fonts
cd ~/.local/share/fonts

Baixe a MesloLGS NF (recomendada para agnoster):

wget https://github.com/ryanoasis/nerd-fonts/releases/latest/download/Meslo.zip
unzip Meslo.zip
fc-cache -fv

Configure seu terminal para usar a fonte MesloLGS NF Regular.

🔌 Adicionando Plugins Úteis

zsh-autosuggestions

Clone o plugin:

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

Ativando os plugins

Edite .zshrc:

nano ~/.zshrc

Modifique a linha plugins= para incluir:

plugins=(git ssh-agent zsh-autosuggestions)

Salve e aplique:

source ~/.zshrc

🔐 Configurando SSH com o GitHub

Gere uma nova chave SSH:

ssh-keygen -t ed25519 -C "seu-email@exemplo.com"

Pressione Enter para usar o caminho padrão. Defina uma senha (opcional).

Inicie o agente SSH:

eval "$(ssh-agent -s)"

Adicione a chave ao agente:

ssh-add ~/.ssh/id_ed25519

Copie a chave pública:

cat ~/.ssh/id_ed25519.pub

Ou, com xclip (instale se necessário):

xclip -sel clip < ~/.ssh/id_ed25519.pub

Adicione a chave à sua conta GitHub em:
Settings > SSH and GPG Keys > New SSH key

Teste a conexão:

ssh -T git@github.com

Saída esperada:

Hi seu-usuario! You've successfully authenticated, but GitHub does not provide shell access.

✅ Testando a Configuração

  • O terminal deve exibir o tema agnoster com ícones corretos.
  • Plugins:
    • zsh-autosuggestions: Sugestões aparecem ao digitar.
    • git: Teste gst (atalho para git status).
    • ssh-agent: Confirme com ssh-add -l.

🛠️ Dicas de Solução de Problemas

ProblemaSolução
Ícones não aparecemVerifique a fonte MesloLGS NF no terminal. Reinstale se necessário.
zsh-autosuggestions não funcionaConfirme que o plugin foi clonado corretamente e está listado no .zshrc.
Erro ao conectar ao GitHub via SSHVerifique se a chave foi adicionada e carregada com ssh-add -l.
Comandos como wget ou unzip não encontradosInstale com sudo apt install wget unzip.
Zsh não é shell padrãoExecute chsh -s $(which zsh) e reinicie o terminal.

🎉 Conclusão

Parabéns! Você configurou um terminal Zsh com:

  • Oh My Zsh com o tema agnoster
  • Nerd Font para ícones compatíveis
  • ✅ Plugins úteis: git, ssh-agent, zsh-autosuggestions
  • ✅ Conexão SSH segura com o GitHub

Explore mais temas e plugins no site oficial:
🔗 https://ohmyz.sh