From 7a263fa5f154f0735db4e64fc70322096dfa76fc Mon Sep 17 00:00:00 2001 From: rain Date: Mon, 7 Sep 2026 03:29:50 -0400 Subject: [PATCH] zsh: adopt deja predictive autosuggestions; make deja install version-aware - .zshrc: replace the zsh-autosuggestions plugin with deja (deja supersedes it), and move the auto-dedup PATH block to the top so ~/.local/bin is on PATH before plugins/modules load. - bootstrap scripts (arch/debian + gentoo): clone the deja OMZ plugin and install the deja binary via the official checksum-verified installer. The binary install now compares the installed version to the latest release tag and re-runs the installer when they differ, so re-running the script UPGRADES deja (0.4.1 -> 0.4.2) rather than skipping an existing install. --- dot_zshrc.tmpl | 27 +++++------ ...ce_20-install-user-packages-gentoo.sh.tmpl | 40 +++++++++++++++- run_once_20-install-user-packages.sh.tmpl | 46 ++++++++++++++++++- 3 files changed, 98 insertions(+), 15 deletions(-) diff --git a/dot_zshrc.tmpl b/dot_zshrc.tmpl index b53821c..217c34a 100644 --- a/dot_zshrc.tmpl +++ b/dot_zshrc.tmpl @@ -4,6 +4,19 @@ # Sync source: https://git.melonbread.xyz/rain/gnu-plus-dotfiles # ============================================================================= +# --------------------------------------------------------------------------- +# PATH (auto-deduplicated) +# --------------------------------------------------------------------------- +typeset -U path +path=( + {{- if not (not (stat "/opt/rocm/bin")) }} + /opt/rocm/bin # ROCm tools first (rocminfo, rocm-smi, amd-smi, hipcc, etc.) + {{- end }} + $HOME/.local/bin + $HOME/.bin + $path +) + # --------------------------------------------------------------------------- # Oh My Zsh # --------------------------------------------------------------------------- @@ -25,7 +38,7 @@ plugins=( fzf-tab # navigable Tab completion menu zsh-syntax-highlighting # fish-style live colors — MUST be near last zsh-history-substring-search # fish-style Up/Down history search - zsh-autosuggestions # fish-style ghost completions — MUST be last + deja # predictive ghost completions — MUST be last (replaces zsh-autosuggestions) ) @@ -85,18 +98,6 @@ export TMUX_PLUGIN_MANAGER_PATH=~/.tmux/plugins/tpm # Debian: ROCm only relevant if you install it. Leave default until needed. {{ end -}} -# --------------------------------------------------------------------------- -# PATH (auto-deduplicated) -# --------------------------------------------------------------------------- -typeset -U path -path=( - {{- if not (not (stat "/opt/rocm/bin")) }} - /opt/rocm/bin # ROCm tools first (rocminfo, rocm-smi, amd-smi, hipcc, etc.) - {{- end }} - $HOME/.local/bin - $HOME/.bin - $path -) # --------------------------------------------------------------------------- # Aliases — common + OS-specific diff --git a/run_once_20-install-user-packages-gentoo.sh.tmpl b/run_once_20-install-user-packages-gentoo.sh.tmpl index 083ce22..e67c0d6 100644 --- a/run_once_20-install-user-packages-gentoo.sh.tmpl +++ b/run_once_20-install-user-packages-gentoo.sh.tmpl @@ -239,12 +239,13 @@ else log "oh-my-zsh already installed" fi -# Plugins: zsh-autosuggestions, zsh-syntax-highlighting, zsh-history-substring-search, fzf-tab +# Plugins: zsh-autosuggestions, zsh-syntax-highlighting, zsh-history-substring-search, fzf-tab, deja declare -A PLUGINS=( [zsh-autosuggestions]="https://github.com/zsh-users/zsh-autosuggestions" [zsh-syntax-highlighting]="https://github.com/zsh-users/zsh-syntax-highlighting" [zsh-history-substring-search]="https://github.com/zsh-users/zsh-history-substring-search" [fzf-tab]="https://github.com/Aloxaf/fzf-tab" + [deja]="https://github.com/Giammarco-Ferranti/deja" ) for plugin in "${!PLUGINS[@]}"; do if [[ -d "$ZSH_CUSTOM/plugins/$plugin" ]]; then @@ -255,6 +256,43 @@ for plugin in "${!PLUGINS[@]}"; do fi done +# deja predictive autosuggestions: binary via official installer (into +# ~/.local/bin), then seed DB from history. SHELL neutralized so the +# installer never touches .zshrc — the plugin above handles activation. +# The installer always fetches the LATEST release, so this also UPGRADES an +# existing install (0.4.1 -> 0.4.2) when the installed version lags the +# latest release tag — not just a first-run bootstrap. +DEJA_BIN="$USER_HOME/.local/bin/deja" +deja_install_or_upgrade() { + log "installing/upgrading deja binary via official installer" + curl -fsSL https://raw.githubusercontent.com/Giammarco-Ferranti/deja/main/install.sh \ + | INSTALL_DIR="$USER_HOME/.local/bin" SHELL=/bin/sh sh \ + || log "WARNING: deja install failed; retry manually." + log "deja now: $("$DEJA_BIN" --version 2>/dev/null | head -1)" +} +if command -v deja >/dev/null 2>&1; then + INSTALLED_VER="$(deja --version 2>/dev/null | awk '{print $2}')" + LATEST_TAG="$(curl -fsSL https://api.github.com/repos/Giammarco-Ferranti/deja/releases/latest 2>/dev/null \ + | grep '"tag_name":' | head -n1 | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')" + LATEST_VER="${LATEST_TAG#v}" + if [[ -z "$LATEST_VER" ]]; then + log "deja present ($INSTALLED_VER); could not check latest, leaving as-is" + elif [[ "$INSTALLED_VER" == "$LATEST_VER" ]]; then + log "deja already at latest ($INSTALLED_VER)" + else + log "deja $INSTALLED_VER != latest $LATEST_TAG — upgrading" + deja_install_or_upgrade + fi +else + log "deja not installed; installing" + deja_install_or_upgrade +fi +if command -v deja >/dev/null 2>&1 && [[ ! -s "$USER_HOME/.local/share/deja/deja.db" ]]; then + log "seeding deja DB from shell history" + HISTFILE="${HISTFILE:-$USER_HOME/.zsh_history}" deja import \ + || log "WARNING: deja import failed; run 'deja import' later." +fi + # Step 8: tpm (tmux plugin manager) if [[ ! -d "$USER_HOME/.tmux/plugins/tpm" ]]; then log "installing tpm" diff --git a/run_once_20-install-user-packages.sh.tmpl b/run_once_20-install-user-packages.sh.tmpl index cab0f43..3c7fb6d 100755 --- a/run_once_20-install-user-packages.sh.tmpl +++ b/run_once_20-install-user-packages.sh.tmpl @@ -6,7 +6,8 @@ # starship, lazygit, yt-dlp, etc.) # # Also: install oh-my-zsh, zsh-autosuggestions, zsh-syntax-highlighting, -# zsh-history-substring-search, fzf-tab. +# zsh-history-substring-search, fzf-tab, and the deja autosuggestion engine +# (binary via official installer + plugin clone). # # Runs as the unprivileged user, but uses sudo for system packages. # @@ -277,6 +278,49 @@ install_zsh_plugin zsh-users/zsh-syntax-highlighting "$ZSH_CUSTOM/plugins/zsh install_zsh_plugin zsh-users/zsh-history-substring-search "$ZSH_CUSTOM/plugins/zsh-history-substring-search" install_zsh_plugin Aloxaf/fzf-tab "$ZSH_CUSTOM/plugins/fzf-tab" +install_zsh_plugin Giammarco-Ferranti/deja "$ZSH_CUSTOM/plugins/deja" +# --------------------------- deja (predictive autosuggestions) ------------- +# Binary via the official installer (checksum-verified release tarball into +# ~/.local/bin). SHELL is neutralized so the installer never appends its +# activation block to .zshrc — the OMZ plugin cloned above handles that. +# The installer always fetches the LATEST release, so this block also +# UPGRADES an existing install (0.4.1 -> 0.4.2), not just bootstraps a fresh +# one: we compare the installed version to the latest release tag and re-run +# the installer when they differ. `deja import` seeds the suggestion DB from +# $HISTFILE (falls back to ~/.zsh_history); safe to re-run, it dedupes. +DEJA_BIN="$USER_HOME/.local/bin/deja" +deja_install_or_upgrade() { + log "installing/upgrading deja binary via official installer" + if curl -fsSL https://raw.githubusercontent.com/Giammarco-Ferranti/deja/main/install.sh \ + | INSTALL_DIR="$USER_HOME/.local/bin" SHELL=/bin/sh sh; then + log "deja now: $("$DEJA_BIN" --version 2>/dev/null | head -1)" + else + log "WARNING: deja install failed; zsh-autosuggestions behavior will be absent. Retry manually." + fi +} +if command -v deja >/dev/null 2>&1; then + INSTALLED_VER="$(deja --version 2>/dev/null | awk '{print $2}')" + LATEST_TAG="$(curl -fsSL https://api.github.com/repos/Giammarco-Ferranti/deja/releases/latest 2>/dev/null \ + | grep '"tag_name":' | head -n1 | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')" + LATEST_VER="${LATEST_TAG#v}" + if [[ -z "$LATEST_VER" ]]; then + log "deja present ($INSTALLED_VER); could not check latest, leaving as-is" + elif [[ "$INSTALLED_VER" == "$LATEST_VER" ]]; then + log "deja already at latest ($INSTALLED_VER)" + else + log "deja $INSTALLED_VER != latest $LATEST_TAG — upgrading" + deja_install_or_upgrade + fi +else + log "deja not installed; installing" + deja_install_or_upgrade +fi +if command -v deja >/dev/null 2>&1 && [[ ! -s "$USER_HOME/.local/share/deja/deja.db" ]]; then + log "seeding deja DB from shell history" + HISTFILE="${HISTFILE:-$USER_HOME/.zsh_history}" deja import \ + || log "WARNING: deja import failed; run 'deja import' in an interactive shell later." +fi + # --------------------------- TPM (tmux plugin manager) --------------------- if [[ ! -d "$USER_HOME/.tmux/plugins/tpm" ]]; then log "cloning tmux plugin manager"