Skip to content

Instantly share code, notes, and snippets.

@cfobel
Created May 29, 2025 14:43
Show Gist options
  • Save cfobel/4e975a4e205dd2831b46f49455b29380 to your computer and use it in GitHub Desktop.
Save cfobel/4e975a4e205dd2831b46f49455b29380 to your computer and use it in GitHub Desktop.
Zsh dev shell bootstrap
#!/usr/bin/env zsh
# Zsh bootstrap script
# See: https://chatgpt.com/share/67206e10-24f8-800c-9b0e-cfc4998e4960
# Function to append or create file based on user confirmation
update_file() {
local file=$1
local content=$2
if [ -e "$file" ]; then
read -q "?$file already exists. Append/update it? (y/n) " choice
echo
if [[ $choice =~ ^[Yy]$ ]]; then
print "Updating $file..."
print -r -- "$content" >> "$file"
else
print "Skipping $file..."
fi
else
print "Creating $file..."
print -r -- "$content" > "$file"
fi
}
# ---- Update ~/.zshrc ----
zshrc_content=$(cat << 'EOF'
# Set vim as the default editor
export EDITOR=vim
# Alias for hidden files in 'ls'
alias la="ls -lAh"
# Common aliases (uncomment as needed)
# alias ll="ls -alF"
# alias l="ls -CF"
# alias grep="grep --color=auto"
# alias cls="clear"
alias ..="cd .."
alias ...="cd ../.."
# Use vi-mode in Zsh
bindkey -v
# Use up/down arrow to search history for prefix
bindkey '^[[A' history-beginning-search-backward
bindkey '^[[B' history-beginning-search-forward
# Share history across all sessions, and append immediately
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt inc_append_history
setopt share_history
# Initialize completion system
autoload -Uz compinit && compinit
# Enable extended globbing (optional)
setopt extended_glob
# Edit current command in $EDITOR via 'v' in vi-command mode
autoload -Uz edit-command-line
zle -N edit-command-line
bindkey -M vicmd 'v' edit-command-line
EOF
)
update_file ~/.zshrc "$zshrc_content"
# ---- Update ~/.tmux.conf ----
tmux_conf_content=$(cat << 'EOF'
# Enable 256 (or higher) color support
set -g default-terminal "screen-256color"
# Use Ctrl+a instead of Ctrl+b
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Vi-style pane navigation
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Pane splits
bind | split-window -h
bind - split-window -v
# Vi keys in copy mode
setw -g mode-keys vi
# Copy-mode bindings
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle
EOF
)
update_file ~/.tmux.conf "$tmux_conf_content"
# ---- Completion ----
print "\nDone! To apply your new Zsh settings, run:"
print " source ~/.zshrc"
print "\nTo apply tmux changes, either start a new session or:"
print " tmux source-file ~/.tmux.conf"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment