reorg and added zinit instead of oh-my-zsh

This commit is contained in:
Jeremie Fraeys 2024-08-22 18:37:58 -04:00
parent 7983863295
commit 15de540152
6 changed files with 121 additions and 201 deletions

View file

@ -20,12 +20,16 @@ chmod -R ug+rwx "$HOME/.local/bin/"
# Read fzf theme options if the file exists # Read fzf theme options if the file exists
if [ -f "$HOME/.local/bin/scripts/fzf_theme" ]; then if [ -f "$HOME/.local/bin/scripts/fzf_theme" ]; then
FZF_OPTIONS=$("$HOME/.local/bin/scripts/fzf_theme") FZF_OPTIONS=$("$HOME/.local/bin/scripts/fzf_theme")
export FZF_DEFAULT_OPTS="$FZF_OPTIONS" export FZF_DEFAULT_OPTS="$FZF_OPTIONS"
fi fi
# Source fzf configuration # Source fzf configuration
source <(fzf --bash) if command -v fzf >/dev/null 2>&1; then
eval "$(fzf --bash)"
fi
[ -f ~/.fzf.bash ] && . ~/.fzf.bash
# Add RVM to PATH # Add RVM to PATH
if [[ ! "$PATH" =~ (^|:)${HOME}/.rvm/bin(:|$) ]]; then if [[ ! "$PATH" =~ (^|:)${HOME}/.rvm/bin(:|$) ]]; then
@ -45,15 +49,15 @@ fi
# >>> conda initialize >>> # >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !! # !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/usr/local/Caskroom/miniforge/base/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" __conda_setup="$('/usr/local/Caskroom/miniforge/base/bin/conda' 'shell.bash' 'hook' 2>/dev/null)"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
eval "$__conda_setup" eval "$__conda_setup"
else else
if [ -f "/usr/local/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then if [ -f "/usr/local/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then
. "/usr/local/Caskroom/miniforge/base/etc/profile.d/conda.sh" . "/usr/local/Caskroom/miniforge/base/etc/profile.d/conda.sh"
else else
export PATH="/usr/local/Caskroom/miniforge/base/bin:$PATH" export PATH="/usr/local/Caskroom/miniforge/base/bin:$PATH"
fi fi
fi fi
unset __conda_setup unset __conda_setup
# <<< conda initialize <<< # <<< conda initialize <<<

View file

@ -1,58 +1,3 @@
# 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=: read -r -a arr <<<"${!var}:"
# Declare an associative array to keep track of seen paths
declare -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"
}
# Load bash completion # Load bash completion
if [[ -f /etc/bash_completion ]]; then if [[ -f /etc/bash_completion ]]; then
. /etc/bash_completion . /etc/bash_completion
@ -69,11 +14,18 @@ fi
# Set the default editor # Set the default editor
export EDITOR='nvim' export EDITOR='nvim'
# Add eza completions to BASH_COMPLETION # Add eza completions to BASH_COMPLETION if not already included
[[ ! "$BASH_COMPLETION" =~ (^|:)${HOME}/.local/bin/eza/completions/bash(:|$) ]] && export BASH_COMPLETION="$HOME/.local/bin/eza/completions/bash:$BASH_COMPLETION" if [[ ! "$BASH_COMPLETION" =~ (^|:)${HOME}/.local/bin/eza/completions/bash(:|$) ]]; then
export BASH_COMPLETION="$HOME/.local/bin/eza/completions/bash:$BASH_COMPLETION"
fi
# Initialize zoxide # Initialize zoxide
eval "$(zoxide init bash)" if command -v zoxide &>/dev/null; then
eval "$(zoxide init bash)"
fi
path_clean # Initialize Starship
if command -v starship &>/dev/null; then
eval "$(starship init bash)"
fi

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Check for Git # Check for Git
if ! command -v git &> /dev/null; then if ! command -v git &>/dev/null; then
echo "Git is not installed. Aborting." >&2 echo "Git is not installed. Aborting." >&2
exit 1 exit 1
fi fi
@ -67,15 +67,18 @@ stowit() {
# -R recursive # -R recursive
# -t target # -t target
# --ignore files to ignore # --ignore files to ignore
stow -v -R -t "${usr}" --ignore "$(IFS="|"; echo "${ignore_files[*]}")" "${app}" stow -v -R -t "${usr}" --ignore "$(
IFS="|"
echo "${ignore_files[*]}"
)" "${app}"
} }
# Function to check if the OS is macOS # Function to check if the OS is macOS
get_os() { get_os() {
case "$(uname)" in case "$(uname)" in
Darwin) echo "macos";; Darwin) echo "macos" ;;
Linux) echo "linux";; Linux) echo "linux" ;;
*) echo "unknown";; *) echo "unknown" ;;
esac esac
} }
@ -110,24 +113,25 @@ for app in "${base[@]}"; do
stowit "${HOME}" "${app}" stowit "${HOME}" "${app}"
done done
case get_os in current_os=$(get_os)
"macos") case "${current_os}" in
for app in "${useronly_macos[@]}"; do "macos")
if [ "$(id -u)" -ne 0 ]; then for app in "${useronly_macos[@]}"; do
stowit "${HOME}" "${app}" if [ "$(id -u)" -ne 0 ]; then
fi stowit "${HOME}" "${app}"
done fi
;; done
"linux") ;;
for app in "${useronly_linux[@]}"; do "linux")
if [ "$(id -u)" -ne 0 ]; then for app in "${useronly_linux[@]}"; do
stowit "${HOME}" "${app}" if [ "$(id -u)" -ne 0 ]; then
fi stowit "${HOME}" "${app}"
done fi
;; done
"unknown") ;;
echo "Unknown OS." "unknown")
;; echo "Unknown OS."
;;
esac esac
# Setup useronly folders # Setup useronly folders

View file

@ -2,7 +2,7 @@
"$schema" = 'https://starship.rs/config-schema.json' "$schema" = 'https://starship.rs/config-schema.json'
add_newline = false add_newline = false
palette = "solarized_light" palette = "monokai_pro"
command_timeout = 1000 command_timeout = 1000
# Customize your prompt to ensure everything is on a single line # Customize your prompt to ensure everything is on a single line

View file

@ -8,16 +8,16 @@ export PAGER="less -i -N -S -R"
if [[ -n "$PYENV_ROOT" && ! "$PATH" =~ (^|:)${PYENV_ROOT}/bin(:|$) ]]; then if [[ -n "$PYENV_ROOT" && ! "$PATH" =~ (^|:)${PYENV_ROOT}/bin(:|$) ]]; then
export PATH="$PYENV_ROOT/bin:$PATH" export PATH="$PYENV_ROOT/bin:$PATH"
fi fi
eval "$(pyenv init -)"
if command -v pyenv >/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
# Add ~/.local/bin to PATH if it exists # Add ~/.local/bin to PATH if it exists
if [[ -d "$HOME/.local/bin" && ! "$PATH" =~ (^|:)${HOME}/.local/bin(:|$) ]]; then if [[ -d "$HOME/.local/bin" && ! "$PATH" =~ (^|:)${HOME}/.local/bin(:|$) ]]; then
export PATH="$HOME/.local/bin:$PATH" export PATH="$HOME/.local/bin:$PATH"
fi fi
# Set permissions for ~/.local/bin
chmod -R ug+rwx "$HOME/.local/bin/"
# Read fzf theme options if the file exists # Read fzf theme options if the file exists
if [[ -f "$HOME/.local/bin/scripts/fzf_theme" ]]; then if [[ -f "$HOME/.local/bin/scripts/fzf_theme" ]]; then
FZF_OPTIONS=$("$HOME/.local/bin/scripts/fzf_theme") FZF_OPTIONS=$("$HOME/.local/bin/scripts/fzf_theme")
@ -25,16 +25,20 @@ if [[ -f "$HOME/.local/bin/scripts/fzf_theme" ]]; then
fi fi
# Source fzf configuration # Source fzf configuration
source <(fzf --zsh) if command -v fzf >/dev/null 2>&1; then
eval "$(fzf --zsh)"
fi
[ -f ~/.fzf.zsh ] && . ~/.fzf.zsh
# Add RVM to PATH # Add RVM to PATH
if [[ ! "$PATH" =~ (^|:)${HOME}/.rvm/bin(:|$) ]]; then if [[ -d "$HOME/.rvm/bin" && ! "$PATH" =~ (^|:)${HOME}/.rvm/bin(:|$) ]]; then
export PATH="$PATH:$HOME/.rvm/bin" export PATH="$PATH:$HOME/.rvm/bin"
fi fi
# Add Golang to PATH # Add Golang to PATH
if [[ -n "$(go env GOPATH)" && ! "$PATH" =~ (^|:)$(go env GOPATH)/bin(:|$) ]]; then if [[ -n "$(go env GOPATH)" && ! "$PATH" =~ (^|:)$(go env GOPATH)/bin(:|$) ]]; then
export GOPATH="$HOME/Documents/projects:$HOME/go" export GOPATH="${GOPATH:-$HOME/Documents/projects:$HOME/.go}"
export PATH="$PATH:$(go env GOPATH)/bin" export PATH="$PATH:$(go env GOPATH)/bin"
fi fi

View file

@ -1,70 +1,10 @@
# Enable profiling
# zmodload zsh/zprof # 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 # Path to your oh-my-zsh installation
export ZSH="$HOME/.oh-my-zsh" # export ZSH="$HOME/.oh-my-zsh"
export ZSH_CUSTOM="$HOME/.oh-my-zsh/custom" # export ZSH_CUSTOM="$HOME/.oh-my-zsh/custom"
export UPDATE_ZSH_DAYS=1 # export UPDATE_ZSH_DAYS=1
# Add macOS specific command-line utilities # Add macOS specific command-line utilities
if [[ -d /usr/local/opt/coreutils/libexec/gnubin && ! "$PATH" =~ (^|:)/usr/local/opt/coreutils/libexec/gnubin(:|$) ]]; then if [[ -d /usr/local/opt/coreutils/libexec/gnubin && ! "$PATH" =~ (^|:)/usr/local/opt/coreutils/libexec/gnubin(:|$) ]]; then
@ -84,12 +24,12 @@ for dir in "${dirs[@]}"; do
fi fi
done done
# Clean up paths again to ensure no duplicates # Disable auto title
path_clean PATH DISABLE_AUTO_TITLE="true"
# Auto-update and other zsh settings # Auto-update and other zsh settings
DISABLE_UPDATE_PROMPT=true # DISABLE_UPDATE_PROMPT=true
zstyle ':omz:update' mode reminder # remind to update # zstyle ':omz:update' mode reminder # remind to update
# Uncomment to use case-sensitive completion # Uncomment to use case-sensitive completion
# CASE_SENSITIVE="true" # CASE_SENSITIVE="true"
@ -100,35 +40,60 @@ zstyle ':omz:update' mode reminder # remind to update
# Miscellaneous configurations # Miscellaneous configurations
# DISABLE_MAGIC_FUNCTIONS="true" # DISABLE_MAGIC_FUNCTIONS="true"
# DISABLE_LS_COLORS="true" # DISABLE_LS_COLORS="true"
# DISABLE_AUTO_TITLE="true"
# ENABLE_CORRECTION="true" # ENABLE_CORRECTION="true"
# COMPLETION_WAITING_DOTS="true" # COMPLETION_WAITING_DOTS="true"
# DISABLE_UNTRACKED_FILES_DIRTY="true" # DISABLE_UNTRACKED_FILES_DIRTY="true"
# Load zsh hooks # Load zsh hooks
autoload -Uz add-zsh-hook # autoload -Uz add-zsh-hook
# Load completion scripts # Load zsh completions
autoload -Uz compinit && compinit -C # autoload -Uz compinit && compinit -C
# Plugins to load # Plugins to load
plugins=( # plugins=(
git # git
docker # docker
zsh-syntax-highlighting # zsh-syntax-highlighting
zsh-autosuggestions # zsh-autosuggestions
colored-man-pages # colored-man-pages
macos # macos
autoupdate # autoupdate
zoxide # zoxide
) # )
export ZSH_AUTOSUGGEST_STRATEGY=( # export ZSH_AUTOSUGGEST_STRATEGY=(
history # history
completion # completion
) # )
# Source oh-my-zsh.sh # Source oh-my-zsh.sh
source $ZSH/oh-my-zsh.sh # . $ZSH/oh-my-zsh.sh
# Load zinit
export ZINIT_HOME="${ZDOTDIR:-$HOME}/.zinit"
if [[ ! -d $ZINIT_HOME ]]; then
git clone https://github.com/zdharma-continuum/zinit $ZINIT_HOME
fi
. $ZINIT_HOME/zinit.zsh
# Load plugins with zinit
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-history-substring-search
# zoxide
zinit ice from"gh-r" as"program" pick"bin/zoxide"
zinit load ajeetdsouza/zoxide
# Load eza completions if needed
[[ ! "$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)"
# Initialize Starship # Initialize Starship
eval "$(starship init zsh)" eval "$(starship init zsh)"
@ -163,22 +128,13 @@ fi
alias python="python3" alias python="python3"
alias grep="grep --color=auto" alias grep="grep --color=auto"
alias update_omz="omz update && update_oh_my_zsh_custom"
if [[ -f ~/.local/bin/scripts/check_aliases ]]; then if [[ -f ~/.local/bin/scripts/check_aliases ]]; then
source ~/.local/bin/scripts/check_aliases . ~/.local/bin/scripts/check_aliases
fi fi
# Final clean-up of PATH (commented out for speed)
# path_clean
# zprof (commented out for speed)
# Add eza completions to FPATH # zprof
[[ ! "$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