Aller au contenu

Installation et configuration

Installer Zsh, Oh My Zsh et Starship, puis configurer les plugins essentiels pour un shell productif.


Installer Zsh

Zsh est le shell par defaut depuis macOS Catalina (10.15). Vérifier :

echo $SHELL
# /bin/zsh

Si ce n'est pas le cas :

brew install zsh
chsh -s $(which zsh)
sudo apt update && sudo apt install zsh

# Definir comme shell par defaut
chsh -s $(which zsh)

# Deconnexion/reconnexion pour appliquer
# Dans le terminal WSL
sudo apt update && sudo apt install zsh
chsh -s $(which zsh)

# Redemarrer le terminal Windows Terminal

Vérifier :

zsh --version
# zsh 5.9 (x86_64-...)

Installer Oh My Zsh

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

Oh My Zsh cree ~/.zshrc avec une configuration par defaut.

Installer Starship

Prompt moderne, rapide et configurable — fonctionne avec tout shell :

brew install starship
curl -sS https://starship.rs/install.sh | sh
curl -sS https://starship.rs/install.sh | sh

Activer dans ~/.zshrc :

# Ajouter a la fin de ~/.zshrc
eval "$(starship init zsh)"

Configuration Starship (~/.config/starship.toml) :

# Format compact : repertoire + git + langage + duree
format = """
$directory$git_branch$git_status$python$nodejs$golang$rust$cmd_duration
$character"""

[directory]
truncation_length = 3
truncate_to_repo = true

[git_branch]
format = "[$branch]($style) "

[git_status]
format = "[$all_status$ahead_behind]($style) "

[cmd_duration]
min_time = 2000
format = "[$duration]($style) "

[character]
success_symbol = "[❯](green)"
error_symbol = "[❯](red)"

Plugins essentiels

Installer les plugins tiers :

# Autosuggestions — suggestions grisees basees sur l'historique
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# Syntax highlighting — coloration des commandes dans le prompt
git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

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

Activer dans ~/.zshrc :

plugins=(
  git                      # Aliases git (gst, gco, gp...)
  zsh-autosuggestions      # Suggestions de l'historique
  zsh-syntax-highlighting  # Coloration des commandes
  zsh-completions          # Completions supplementaires
  docker                   # Completion Docker
  kubectl                  # Completion Kubernetes
)

Recharger :

source ~/.zshrc

Configuration .zshrc recommandee

# ~/.zshrc — configuration de reference

# Oh My Zsh
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME=""  # Desactive le theme OMZ (on utilise Starship)

plugins=(
  git
  zsh-autosuggestions
  zsh-syntax-highlighting
  zsh-completions
  docker
  kubectl
)

source $ZSH/oh-my-zsh.sh

# Editeur
export EDITOR="code --wait"
export VISUAL="$EDITOR"

# Historique
HISTSIZE=50000
SAVEHIST=50000
setopt HIST_IGNORE_DUPS      # Pas de doublons consecutifs
setopt HIST_IGNORE_ALL_DUPS  # Supprimer les anciens doublons
setopt HIST_FIND_NO_DUPS     # Pas de doublons dans la recherche
setopt SHARE_HISTORY         # Partager l'historique entre sessions

# Prompt Starship
eval "$(starship init zsh)"

Vérification

Ouvrir un nouveau terminal et vérifier :

  1. Le prompt Starship s'affiche avec le répertoire et la branche Git
  2. Taper git s → une suggestion grisee apparait (git status)
  3. Appuyer sur Right pour accepter la suggestion
  4. Taper une commande invalide → elle s'affiche en rouge (syntax highlighting)