.dotfiles/zsh/.zshrc
2024-08-20 01:26:31 -04:00

184 lines
4.4 KiB
Bash
Executable file

# zmodload zsh/zprof
# Function to clean up and normalize paths
path_print_clean() {
local var=${1:-PATH}
local arr
local newarr=()
local path
local p
# Read PATH into an array
IFS=: arr=(${(s.:.)${(P)var}})
# Declare an associative array to keep track of seen paths
typeset -A seen
for p in "${arr[@]}"; do
# Empty element is equivalent to CWD (weird, I know), remove it
if [[ -z $p ]]; then
continue
fi
# Remove any relative paths
if [[ ${p:0:1} != '/' ]]; then
continue
fi
# Normalize path and ensure we can access it
path=$(cd "$p" &>/dev/null && pwd)
# Path doesn't exist or we can't access it
if [[ -z $path ]]; then
continue
fi
# Filter out dups while we are here
if [[ -n ${seen[$path]} ]]; then
continue
fi
seen[$path]=true
# Store the new path
newarr+=("$path")
done
local IFS=:
echo "${newarr[*]}"
}
# Function to clean up the PATH variable
path_clean() {
local path
path=$(path_print_clean) || return 1
# Use eval to correctly assign the cleaned path to the PATH variable
export PATH="$path"
}
timezsh() {
shell=${1-$SHELL}
for i in $(seq 1 10); do /usr/bin/time $shell -i -c exit; done
}
# Path to your oh-my-zsh installation
export ZSH="$HOME/.oh-my-zsh"
export ZSH_CUSTOM="$HOME/.oh-my-zsh/custom"
export UPDATE_ZSH_DAYS=1
# Add macOS specific command-line utilities
if [[ -d /usr/local/opt/coreutils/libexec/gnubin && ! "$PATH" =~ (^|:)/usr/local/opt/coreutils/libexec/gnubin(:|$) ]]; then
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
fi
# Ensure /opt/homebrew is in the PATH if it exists
if [[ -d /opt/homebrew && ! "$PATH" =~ (^|:)/opt/homebrew/(bin|sbin)($|:) ]]; then
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
fi
# Add /usr/local/bin and /usr/local/sbin to PATH if they are not already present
dirs=("/usr/local/bin" "/usr/local/sbin")
for dir in "${dirs[@]}"; do
if [[ -d $dir && ! "$PATH" =~ (^|:)$dir(:|$) ]]; then
export PATH="$dir:$PATH"
fi
done
# Clean up paths again to ensure no duplicates
path_clean PATH
# Auto-update and other zsh settings
DISABLE_UPDATE_PROMPT=true
zstyle ':omz:update' mode reminder # remind to update
# Uncomment to use case-sensitive completion
# CASE_SENSITIVE="true"
# Uncomment to use hyphen-insensitive completion
# HYPHEN_INSENSITIVE="true"
# Miscellaneous configurations
# DISABLE_MAGIC_FUNCTIONS="true"
# DISABLE_LS_COLORS="true"
# DISABLE_AUTO_TITLE="true"
# ENABLE_CORRECTION="true"
# COMPLETION_WAITING_DOTS="true"
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Load zsh hooks
autoload -Uz add-zsh-hook
# Load completion scripts
autoload -Uz compinit && compinit -C
# Plugins to load
plugins=(
git
docker
zsh-syntax-highlighting
zsh-autosuggestions
colored-man-pages
macos
autoupdate
zoxide
)
export ZSH_AUTOSUGGEST_STRATEGY=(
history
completion
)
# Source oh-my-zsh.sh
source $ZSH/oh-my-zsh.sh
# Initialize Starship
eval "$(starship init zsh)"
export STARSHIP_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/starship.toml"
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/usr/local/Caskroom/miniforge/base/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/usr/local/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then
. "/usr/local/Caskroom/miniforge/base/etc/profile.d/conda.sh"
else
export PATH="/usr/local/Caskroom/miniforge/base/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
# Set default editor
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='vi'
else
export EDITOR='nvim'
fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Custom aliases
alias python="python3"
alias grep="grep --color=auto"
alias update_omz="omz update && update_oh_my_zsh_custom"
if [[ -f ~/.local/bin/scripts/check_aliases ]]; then
source ~/.local/bin/scripts/check_aliases
fi
# Add eza completions to FPATH
[[ ! "$FPATH" =~ (^|:)${HOME}/.local/bin/eza/completions/zsh(:|$) ]] && export FPATH="$HOME/.local/bin/eza/completions/zsh:$FPATH"
#Initialize direnv
eval "$(direnv hook zsh)"
# Initialize zoxide
eval "$(zoxide init --cmd cd zsh)"
path_clean