refractor(dotfile): divers amelioration

This commit is contained in:
Anael Ginder
2026-09-18 15:59:25 +02:00
parent 83a78c098b
commit a17efb819f
2 changed files with 172 additions and 84 deletions
+107 -23
View File
@@ -69,12 +69,12 @@ if ! command -v cargo >/dev/null 2>&1; then
fi
# ------------------------------------------------------------
# Spaceship prompt
# Spaceship
#
# Le logiciel est installé séparément dans :
# Logiciel :
# ~/.zsh/spaceship-prompt
#
# La configuration personnelle est gérée par Stow :
# Configuration :
# ~/.zsh/spaceship.zsh
# ------------------------------------------------------------
@@ -100,7 +100,7 @@ else
fi
# ------------------------------------------------------------
# Migration des configurations existantes
# Backup
# ------------------------------------------------------------
create_backup_dir() {
@@ -118,28 +118,65 @@ create_backup_dir() {
log "Backup créé dans : $BACKUP_DIR"
}
backup_path_for() {
local target="$1"
local relative_path
relative_path="${target#"$HOME"/}"
printf '%s/%s\n' "$BACKUP_DIR" "$relative_path"
}
backup_if_needed() {
local target="$1"
local expected_source="$2"
# Rien n'existe : Stow pourra créer le lien.
# Rien n'existe.
if [[ ! -e "$target" && ! -L "$target" ]]; then
log "Absent, Stow va le créer : $target"
return
fi
# C'est déjà un symlink.
# On ne le déplace pas et on laisse Stow le gérer.
# --------------------------------------------------------
# Symlink
# --------------------------------------------------------
if [[ -L "$target" ]]; then
log "Symlink déjà présent : $target"
local current_source
current_source="$(readlink -f "$target")"
expected_source="$(readlink -f "$expected_source")"
if [[ "$current_source" == "$expected_source" ]]; then
log "Symlink déjà correct : $target"
return
fi
warn "Symlink existant mais incorrect : $target"
warn " actuel : $current_source"
warn " attendu : $expected_source"
create_backup_dir
local backup_path
backup_path="$(backup_path_for "$target")"
mkdir -p "$(dirname "$backup_path")"
log "Backup du symlink : $target -> $backup_path"
mv -- "$target" "$backup_path"
return
fi
# --------------------------------------------------------
# Fichier ou répertoire normal
# --------------------------------------------------------
create_backup_dir
local relative_path
relative_path="${target#"$HOME"/}"
local backup_path
backup_path="$BACKUP_DIR/$relative_path"
backup_path="$(backup_path_for "$target")"
mkdir -p "$(dirname "$backup_path")"
@@ -148,18 +185,38 @@ backup_if_needed() {
mv -- "$target" "$backup_path"
}
# ------------------------------------------------------------
# Migration des dotfiles
# ------------------------------------------------------------
migrate_dotfiles() {
log "Vérification des configurations existantes..."
# Zsh
backup_if_needed "$HOME/.zshrc"
backup_if_needed "$HOME/.zshrc.perso"
backup_if_needed "$HOME/.zsh/spaceship.zsh"
backup_if_needed \
"$HOME/.zshrc" \
"$DOTFILES_DIR/zsh/dot-zshrc"
backup_if_needed \
"$HOME/.zshrc.perso" \
"$DOTFILES_DIR/zsh/dot-zshrc.perso"
backup_if_needed \
"$HOME/.zsh/spaceship.zsh" \
"$DOTFILES_DIR/zsh/dot-zsh/spaceship.zsh"
# Zellij
backup_if_needed "$HOME/.config/zellij/config.kdl"
backup_if_needed "$HOME/.config/zellij/layouts/default.kdl"
backup_if_needed "$HOME/.config/zellij/plugins/monocle.wasm"
backup_if_needed \
"$HOME/.config/zellij/config.kdl" \
"$DOTFILES_DIR/zellij/dot-config/zellij/config.kdl"
backup_if_needed \
"$HOME/.config/zellij/layouts/default.kdl" \
"$DOTFILES_DIR/zellij/dot-config/zellij/layouts/default.kdl"
backup_if_needed \
"$HOME/.config/zellij/plugins/monocle.wasm" \
"$DOTFILES_DIR/zellij/dot-config/zellij/plugins/monocle.wasm"
}
migrate_dotfiles
@@ -180,20 +237,47 @@ stow \
zellij
# ------------------------------------------------------------
# Outils Rust
# Installation des outils Cargo
# ------------------------------------------------------------
log "Installation des outils Rust..."
install_cargo_package() {
local package="$1"
local command="${2:-$1}"
#cargo install --locked bat bottom diskus procs cargo-update
if command -v "$command" >/dev/null 2>&1; then
log "$package déjà installé."
return
fi
log "Installation de $package..."
cargo install --locked "$package"
}
#install_cargo_package zellij
#install_cargo_package bat
#install_cargo_package bottom
#install_cargo_package diskus
#install_cargo_package procs
# cargo-update installe la commande `cargo-install-update`
if ! command -v cargo-install-update >/dev/null 2>&1; then
log "Installation de cargo-update..."
cargo install --locked cargo-update
else
log "cargo-update déjà installé."
fi
# ------------------------------------------------------------
# Résumé
# ------------------------------------------------------------
if [[ -n "$BACKUP_DIR" ]]; then
log "Les anciennes configurations ont été sauvegardées dans :"
log "Anciennes configurations sauvegardées dans :"
log " $BACKUP_DIR"
else
log "Aucun backup nécessaire."
fi
log "Installation terminée avec succès."
log "Installation terminée avec succès."