Initial commit. Functional zshrc config setup.
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.zshrc.local
|
||||||
|
*.backup.*
|
||||||
186
install.sh
Executable file
186
install.sh
Executable file
@@ -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 <name> 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
|
||||||
7
zsh/fzf.zsh
Normal file
7
zsh/fzf.zsh
Normal file
@@ -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
|
||||||
7
zsh/history.zsh
Normal file
7
zsh/history.zsh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
HISTSIZE=100000
|
||||||
|
SAVEHIST=100000
|
||||||
|
|
||||||
|
setopt SHARE_HISTORY
|
||||||
|
setopt HIST_IGNORE_DUPS
|
||||||
|
setopt HIST_IGNORE_SPACE
|
||||||
|
setopt INC_APPEND_HISTORY
|
||||||
13
zsh/keybindings.zsh
Normal file
13
zsh/keybindings.zsh
Normal file
@@ -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
|
||||||
3
zsh/nvm.zsh
Normal file
3
zsh/nvm.zsh
Normal file
@@ -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"
|
||||||
3
zsh/plugins.zsh
Normal file
3
zsh/plugins.zsh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Optional: autosuggestions
|
||||||
|
# Uncomment the lines below to enable command suggestions
|
||||||
|
# source $ZSH_CUSTOM/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
|
||||||
19
zsh/zshrc
Normal file
19
zsh/zshrc
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user