From de32ca6894aa2b17899e5c633d88fd33eec6df2b Mon Sep 17 00:00:00 2001 From: Jose Jimenez Date: Sun, 25 Jan 2026 10:39:50 +0100 Subject: [PATCH] Initial commit. Functional zshrc config setup. --- .gitignore | 2 + README.md | 0 install.sh | 186 ++++++++++++++++++++++++++++++++++++++++++++ zsh/fzf.zsh | 7 ++ zsh/history.zsh | 7 ++ zsh/keybindings.zsh | 13 ++++ zsh/nvm.zsh | 3 + zsh/plugins.zsh | 3 + zsh/zshrc | 19 +++++ 9 files changed, 240 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 install.sh create mode 100644 zsh/fzf.zsh create mode 100644 zsh/history.zsh create mode 100644 zsh/keybindings.zsh create mode 100644 zsh/nvm.zsh create mode 100644 zsh/plugins.zsh create mode 100644 zsh/zshrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0ec936c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.zshrc.local +*.backup.* diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..377adfd --- /dev/null +++ b/install.sh @@ -0,0 +1,186 @@ +#!/usr/bin/env bash +set -e + +# ==================== +# Defaults +# ==================== +THEME="clean" +ADD_NVM=false +DRY_RUN=false + +DOTFILES_DIR="$(cd "$(dirname "$0")" && pwd)" +ZSH_DIR="$HOME/.zsh" +ZSHRC="$HOME/.zshrc" +ZSHRC_LOCAL="$HOME/.zshrc.local" +ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}" + +# ==================== +# Logging +# ==================== +log_info() { echo "[INFO] $*"; } +log_warn() { echo "[WARN] $*"; } +log_error() { echo "[ERROR] $*" >&2; } + +run() { + if $DRY_RUN; then + log_info "[dry-run] $*" + else + eval "$@" + fi +} + +# ==================== +# Help +# ==================== +print_help() { + cat << 'EOF' +Dotfiles installer (zsh-focused) + +Usage: + ./install.sh [options] + +Options: + --theme Oh My Zsh theme to use (default: clean) + --add-nvm Enable Node Version Manager config + --dry-run Show actions without making changes + --help Show this help and exit + +What this does: + • Symlinks zsh configuration from this repo + • Installs required zsh plugins + • Enables syntax highlighting (green/red commands) + • Enables fzf history search + • Adds ergonomic keybindings + • Works on Ubuntu and Fedora + +Examples: + ./install.sh + ./install.sh --theme robbyrussell + ./install.sh --add-nvm + ./install.sh --theme agnoster --add-nvm --dry-run +EOF +} + +# ==================== +# Argument parsing +# ==================== +while [[ $# -gt 0 ]]; do + case "$1" in + --theme) + THEME="$2" + shift + ;; + --add-nvm) + ADD_NVM=true + ;; + --dry-run) + DRY_RUN=true + ;; + --help) + print_help + exit 0 + ;; + *) + log_error "Unknown option: $1" + exit 1 + ;; + esac + shift +done + +# ==================== +# Preconditions +# ==================== +if [ ! -d "$HOME/.oh-my-zsh" ]; then + log_error "Oh My Zsh is not installed. Install it first." + exit 1 +fi + +# ==================== +# OS detection +# ==================== +log_info "Detecting OS" +if command -v apt >/dev/null 2>&1; then + PKG_INSTALL="sudo apt install -y" +elif command -v dnf >/dev/null 2>&1; then + PKG_INSTALL="sudo dnf install -y" +else + PKG_INSTALL="" +fi + +# ==================== +# Dependencies +# ==================== +log_info "Installing dependencies" +if [ -n "$PKG_INSTALL" ]; then + command -v git >/dev/null 2>&1 || run "$PKG_INSTALL git" + command -v fzf >/dev/null 2>&1 || run "$PKG_INSTALL fzf" +fi + +# ==================== +# Plugins +# ==================== +log_info "Installing zsh-syntax-highlighting" +if [ ! -d "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" ]; then + run "git clone https://github.com/zsh-users/zsh-syntax-highlighting \ + '$ZSH_CUSTOM/plugins/zsh-syntax-highlighting'" +else + log_warn "zsh-syntax-highlighting already installed" +fi + +log_info "Installing zsh-autosuggestions (disabled by default)" +if [ ! -d "$ZSH_CUSTOM/plugins/zsh-autosuggestions" ]; then + run "git clone https://github.com/zsh-users/zsh-autosuggestions \ + '$ZSH_CUSTOM/plugins/zsh-autosuggestions'" +else + log_warn "zsh-autosuggestions already installed" +fi + +# ==================== +# Backup existing files +# ==================== +if [ -f "$ZSHRC" ] && [ ! -L "$ZSHRC" ]; then + log_info "Backing up existing .zshrc" + run "cp '$ZSHRC' '$ZSHRC.backup.$(date +%s)'" +fi + +# ==================== +# Symlinks +# ==================== +log_info "Creating zsh config directory" +run "mkdir -p '$ZSH_DIR'" + +log_info "Linking zsh config files" +run "ln -sf '$DOTFILES_DIR/zsh/zshrc' '$ZSHRC'" +run "ln -sf '$DOTFILES_DIR/zsh/keybindings.zsh' '$ZSH_DIR/keybindings.zsh'" +run "ln -sf '$DOTFILES_DIR/zsh/history.zsh' '$ZSH_DIR/history.zsh'" +run "ln -sf '$DOTFILES_DIR/zsh/fzf.zsh' '$ZSH_DIR/fzf.zsh'" +run "ln -sf '$DOTFILES_DIR/zsh/plugins.zsh' '$ZSH_DIR/plugins.zsh'" + +if $ADD_NVM; then + log_info "Linking NVM config" + run "ln -sf '$DOTFILES_DIR/zsh/nvm.zsh' '$ZSH_DIR/nvm.zsh'" +else + run "rm -f '$ZSH_DIR/nvm.zsh' || true" +fi + +# ==================== +# Theme handling +# ==================== +log_info "Setting theme: $THEME" +if ! $DRY_RUN; then + cat << EOF > "$ZSHRC_LOCAL" +export ZSH_THEME="$THEME" +EOF +else + log_info "[dry-run] would write ~/.zshrc.local with theme $THEME" +fi + +# ==================== +# Done +# ==================== +log_info "Dotfiles installation complete" +log_info "Open a new terminal or run: exec zsh" +if $DRY_RUN; then + log_warn "Dry-run mode enabled — no changes were made" +fi diff --git a/zsh/fzf.zsh b/zsh/fzf.zsh new file mode 100644 index 0000000..3bad8ad --- /dev/null +++ b/zsh/fzf.zsh @@ -0,0 +1,7 @@ +if [ -f /usr/share/fzf/shell/key-bindings.zsh ]; then + source /usr/share/fzf/shell/key-bindings.zsh +elif [ -f /usr/share/doc/fzf/examples/key-bindings.zsh ]; then + source /usr/share/doc/fzf/examples/key-bindings.zsh +elif [ -f ~/.fzf/shell/key-bindings.zsh ]; then + source ~/.fzf/shell/key-bindings.zsh +fi diff --git a/zsh/history.zsh b/zsh/history.zsh new file mode 100644 index 0000000..4ebcf27 --- /dev/null +++ b/zsh/history.zsh @@ -0,0 +1,7 @@ +HISTSIZE=100000 +SAVEHIST=100000 + +setopt SHARE_HISTORY +setopt HIST_IGNORE_DUPS +setopt HIST_IGNORE_SPACE +setopt INC_APPEND_HISTORY diff --git a/zsh/keybindings.zsh b/zsh/keybindings.zsh new file mode 100644 index 0000000..34bc4d9 --- /dev/null +++ b/zsh/keybindings.zsh @@ -0,0 +1,13 @@ +bindkey -e + +# Ctrl + Arrow +bindkey "^[[1;5D" backward-word +bindkey "^[[1;5C" forward-word + +# Ctrl + Backspace / Delete +bindkey '^H' backward-kill-word +bindkey '^[[3;5~' kill-word + +# Alt + Delete +bindkey -M emacs '^[[3;3~' kill-word +bindkey "^[[3~" delete-char diff --git a/zsh/nvm.zsh b/zsh/nvm.zsh new file mode 100644 index 0000000..78302ae --- /dev/null +++ b/zsh/nvm.zsh @@ -0,0 +1,3 @@ +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" diff --git a/zsh/plugins.zsh b/zsh/plugins.zsh new file mode 100644 index 0000000..c6d7f22 --- /dev/null +++ b/zsh/plugins.zsh @@ -0,0 +1,3 @@ +# Optional: autosuggestions +# Uncomment the lines below to enable command suggestions +# source $ZSH_CUSTOM/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh diff --git a/zsh/zshrc b/zsh/zshrc new file mode 100644 index 0000000..eeb2226 --- /dev/null +++ b/zsh/zshrc @@ -0,0 +1,19 @@ +export ZSH="$HOME/.oh-my-zsh" + +ZSH_THEME="${ZSH_THEME:-clean}" + +plugins=( + git + zsh-syntax-highlighting +) + +source $ZSH/oh-my-zsh.sh + +# Modular config +source ~/.zsh/keybindings.zsh +source ~/.zsh/history.zsh +source ~/.zsh/fzf.zsh +source ~/.zsh/plugins.zsh + +# Optional local overrides (not committed) +[ -f ~/.zshrc.local ] && source ~/.zshrc.local