Files
home/.zshrc
T

164 lines
4.0 KiB
Bash
Raw Normal View History

# ~/.zshrc
2026-06-17 19:30:07 +02:00
# =============================================================================
# HELPER FUNCTIONS
# =============================================================================
2026-06-17 19:30:07 +02:00
# Add a directory to PATH with existence check
# Usage: add_to_path /path/to/add [prepend|append]
add_to_path() {
local dir="$1"
local position="${2:-prepend}"
2026-06-17 19:30:07 +02:00
if [[ -d "$dir" ]]; then
case "$position" in
prepend)
export PATH="$dir:$PATH"
;;
append)
export PATH="$PATH:$dir"
;;
*)
echo "Warning: Unknown position '$position' for path '$dir'" >&2
return 1
;;
esac
fi
}
# Source a file with existence and readability check (zsh-friendly)
# Usage: source_file /path/to/file
source_file() {
local file="$1"
if [[ -f "$file" && -r "$file" ]]; then
source "$file"
fi
}
2026-06-17 19:30:07 +02:00
# Eval the output of a command, silently skipping if it fails or produces nothing
# Usage: eval_expr 'pyenv init -'
eval_expr() {
local cmd="$1"
local output
if output="$(eval "$cmd" 2>/dev/null)" && [[ -n "$output" ]]; then
eval "$output"
fi
}
2026-06-17 19:30:07 +02:00
# =============================================================================
# PATH EXTENSIONS
# =============================================================================
2026-06-17 19:30:07 +02:00
# Define all path extensions in an array for easy management
path_extensions=(
"$HOME/bin"
"$HOME/.local/bin"
"$HOME/.rbenv/bin"
"$HOME/.pyenv/bin"
"$HOME/.cargo/bin"
"$HOME/go/bin"
"$HOME/scripts"
)
2026-06-17 19:30:07 +02:00
# Apply add_to_path to each directory (prepend by default)
for path_dir in "${path_extensions[@]}"; do
add_to_path "$path_dir" prepend
done
# =============================================================================
# CONFIGURATION FILES TO SOURCE
# =============================================================================
# Define files to source in an array for easy management
source_files=(
"$HOME/.env"
"$HOME/.nvm/nvm.sh"
"$HOME/.cargo/env"
"${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
)
# Source zsh-compatible files (skip if missing, no warnings)
for config_file in "${source_files[@]}"; do
2026-06-19 18:47:29 +02:00
source_file "$config_file"
done
# =============================================================================
# EVAL EXPRESSIONS
# =============================================================================
# Commands whose output should be eval'd (tool initializers, etc.)
eval_expressions=(
'pyenv init -'
)
for expr in "${eval_expressions[@]}"; do
eval_expr "$expr"
done
# =============================================================================
# SHELL INITIALIZATION
# =============================================================================
# Oh My Zsh installation
2026-06-17 19:30:07 +02:00
export ZSH="$HOME/.oh-my-zsh"
# Set theme
2026-06-17 19:30:07 +02:00
ZSH_THEME="powerlevel10k/powerlevel10k"
# Enable plugins
plugins=(
git pm2 gh sudo ssh ruby rust python node github rsync nvm rbenv pyenv
docker docker-compose qrcode zsh-autosuggestions zsh-syntax-highlighting
zsh-interactive-cd zsh-navigation-tools
)
2026-06-17 19:30:07 +02:00
2026-06-19 20:16:38 +02:00
# Add fpath custom completions
2026-06-19 20:32:45 +02:00
[[ -d "$HOME/.zsh/completions" ]] && fpath=("$HOME/.zsh/completions" $fpath)
2026-06-19 20:16:38 +02:00
# Load Oh My Zsh framework
2026-06-19 20:32:45 +02:00
[[ -f "$ZSH/oh-my-zsh.sh" ]] && source "$ZSH/oh-my-zsh.sh"
2026-06-17 19:30:07 +02:00
# Powerlevel10k configuration (must come after theme is set)
2026-06-19 20:32:45 +02:00
[[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh
2026-06-17 19:30:07 +02:00
# =============================================================================
# SHELL OPTIONS
# =============================================================================
2026-06-17 19:30:07 +02:00
zsh_options=(
appendhistory
incappendhistory
sharehistory
histignoreall_dups
histreduceblanks
complete_in_word
always_to_end
prompt_percent
prompt_subst
auto_cd
)
2026-06-17 19:30:07 +02:00
for opt in "${zsh_options[@]}"; do
setopt "$opt"
done
2026-06-17 19:30:07 +02:00
# =============================================================================
# ALIASES AND FUNCTIONS
# =============================================================================
2026-06-17 19:30:07 +02:00
# Please add your custom aliases and functions here or in:
2026-06-17 19:30:07 +02:00
# - $ZSH_CUSTOM/aliases.zsh
# - $ZSH_CUSTOM/functions.zsh
2026-06-17 19:30:07 +02:00
alias arty="arty.sh"
alias stacks="stacks.sh"