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
if [ -f "$HOME/.local/bin/scripts/fzf_theme" ]; then
FZF_OPTIONS=$("$HOME/.local/bin/scripts/fzf_theme")
export FZF_DEFAULT_OPTS="$FZF_OPTIONS"
FZF_OPTIONS=$("$HOME/.local/bin/scripts/fzf_theme")
export FZF_DEFAULT_OPTS="$FZF_OPTIONS"
fi
# 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
if [[ ! "$PATH" =~ (^|:)${HOME}/.rvm/bin(:|$) ]]; then
@ -45,15 +49,15 @@ fi
# >>> conda initialize >>>
# !! 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
eval "$__conda_setup"
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
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 <<<

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
if [[ -f /etc/bash_completion ]]; then
. /etc/bash_completion
@ -69,11 +14,18 @@ fi
# Set the default editor
export EDITOR='nvim'
# Add eza completions to BASH_COMPLETION
[[ ! "$BASH_COMPLETION" =~ (^|:)${HOME}/.local/bin/eza/completions/bash(:|$) ]] && export BASH_COMPLETION="$HOME/.local/bin/eza/completions/bash:$BASH_COMPLETION"
# Add eza completions to BASH_COMPLETION if not already included
if [[ ! "$BASH_COMPLETION" =~ (^|:)${HOME}/.local/bin/eza/completions/bash(:|$) ]]; then
export BASH_COMPLETION="$HOME/.local/bin/eza/completions/bash:$BASH_COMPLETION"
fi
# 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
# Check for Git
if ! command -v git &> /dev/null; then
if ! command -v git &>/dev/null; then
echo "Git is not installed. Aborting." >&2
exit 1
fi
@ -67,15 +67,18 @@ stowit() {
# -R recursive
# -t target
# --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
get_os() {
case "$(uname)" in
Darwin) echo "macos";;
Linux) echo "linux";;
*) echo "unknown";;
Darwin) echo "macos" ;;
Linux) echo "linux" ;;
*) echo "unknown" ;;
esac
}
@ -110,24 +113,25 @@ for app in "${base[@]}"; do
stowit "${HOME}" "${app}"
done
case get_os in
"macos")
for app in "${useronly_macos[@]}"; do
if [ "$(id -u)" -ne 0 ]; then
stowit "${HOME}" "${app}"
fi
done
;;
"linux")
for app in "${useronly_linux[@]}"; do
if [ "$(id -u)" -ne 0 ]; then
stowit "${HOME}" "${app}"
fi
done
;;
"unknown")
echo "Unknown OS."
;;
current_os=$(get_os)
case "${current_os}" in
"macos")
for app in "${useronly_macos[@]}"; do
if [ "$(id -u)" -ne 0 ]; then
stowit "${HOME}" "${app}"
fi
done
;;
"linux")
for app in "${useronly_linux[@]}"; do
if [ "$(id -u)" -ne 0 ]; then
stowit "${HOME}" "${app}"
fi
done
;;
"unknown")
echo "Unknown OS."
;;
esac
# Setup useronly folders

View file

@ -2,7 +2,7 @@
"$schema" = 'https://starship.rs/config-schema.json'
add_newline = false
palette = "solarized_light"
palette = "monokai_pro"
command_timeout = 1000
# 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
export PATH="$PYENV_ROOT/bin:$PATH"
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
if [[ -d "$HOME/.local/bin" && ! "$PATH" =~ (^|:)${HOME}/.local/bin(:|$) ]]; then
export PATH="$HOME/.local/bin:$PATH"
fi
# Set permissions for ~/.local/bin
chmod -R ug+rwx "$HOME/.local/bin/"
# Read fzf theme options if the file exists
if [[ -f "$HOME/.local/bin/scripts/fzf_theme" ]]; then
FZF_OPTIONS=$("$HOME/.local/bin/scripts/fzf_theme")
@ -25,16 +25,20 @@ if [[ -f "$HOME/.local/bin/scripts/fzf_theme" ]]; then
fi
# 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
if [[ ! "$PATH" =~ (^|:)${HOME}/.rvm/bin(:|$) ]]; then
if [[ -d "$HOME/.rvm/bin" && ! "$PATH" =~ (^|:)${HOME}/.rvm/bin(:|$) ]]; then
export PATH="$PATH:$HOME/.rvm/bin"
fi
# Add Golang to PATH
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"
fi

View file

@ -1,70 +1,10 @@
# Enable profiling
# 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
# 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
@ -84,12 +24,12 @@ for dir in "${dirs[@]}"; do
fi
done
# Clean up paths again to ensure no duplicates
path_clean PATH
# Disable auto title
DISABLE_AUTO_TITLE="true"
# Auto-update and other zsh settings
DISABLE_UPDATE_PROMPT=true
zstyle ':omz:update' mode reminder # remind to update
# DISABLE_UPDATE_PROMPT=true
# zstyle ':omz:update' mode reminder # remind to update
# Uncomment to use case-sensitive completion
# CASE_SENSITIVE="true"
@ -100,35 +40,60 @@ zstyle ':omz:update' mode reminder # remind to update
# 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
# autoload -Uz add-zsh-hook
# Load completion scripts
autoload -Uz compinit && compinit -C
# Load zsh completions
# 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
)
# 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
# . $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
eval "$(starship init zsh)"
@ -163,22 +128,13 @@ fi
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
. ~/.local/bin/scripts/check_aliases
fi
# Final clean-up of PATH (commented out for speed)
# path_clean
# 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
# zprof (commented out for speed)
# zprof