Add init file timings and lazy load ros2 stuff

This commit is contained in:
Alexander Rosenberg 2025-02-10 23:26:27 -08:00
parent 561596711f
commit b85772067d
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730
2 changed files with 47 additions and 1 deletions

View File

@ -1,5 +1,8 @@
# Main zsh config file
zmodload zsh/datetime
let __init_zsh_start="${EPOCHREALTIME}"
# Enable completions
FPATH="${HOME}/.local/share/zsh/site-functions:${FPATH}"
autoload -U compinit && compinit
@ -255,6 +258,12 @@ source "${ZSH_CONFIG_DIR}/emacs-bookmark.zsh"
# Platform specific stuff
[ -f /usr/bin/pacman ] && source "${ZSH_CONFIG_DIR}/arch.zsh"
# Ros2 instll on arch
if [[ -d /opt/ros/humble/ ]]; then
ZSH_ROS2_ROOT=/opt/ros/humble/
source "${ZSH_CONFIG_DIR}/lazy-ros2.zsh"
fi
# FZF Integration
load_plugin fzf-tab
# Disable sort when completing `git checkout`
@ -308,7 +317,7 @@ setopt histignoredups
# Run fortune and cowsay if we are not in nvim or ssh
if cmd_exists fortune && cmd_exists cowsay; then
[[ -v NVIM ]] || [[ -v SSH_CLIENT ]] || \
[[ -v NVIM ]] || [[ -v SSH_CLIENT ]] || [[ -v INSIDE_EMACS ]] || \
fortune | cowsay -felephant-in-snake -n
fi
@ -316,3 +325,8 @@ fi
unfunction load_plugin
unfunction cmd_exists
unfunction source_user_file
(( ZSH_INIT_TIME="${EPOCHREALTIME}" - __init_zsh_start ))
function zsh-init-time {
printf 'Zsh initialization took: %05fms\n' "$(( ZSH_INIT_TIME * 1000 ))"
}

32
lazy-ros2.zsh Normal file
View File

@ -0,0 +1,32 @@
# Lazy-load ros2 stuff
(( ${+ZSH_ROS2_ROOT} )) || return
local defined=()
local file
for file in "${ZSH_ROS2_ROOT}/bin/"*; do
local base="${file:t}"
hash -- "${base}" 2>/dev/null && continue
defined+=("${base}")
done
local undef_args=() def
for def in ${defined}; do
undef_args+=("${(q)def}")
done
local exec
for exec in ${defined}; do
eval "
function \${(q)exec} {
printf 'Setting up ros2 with \"%s\"...\n\n' \\
\"\${(q)ZSH_ROS2_ROOT%/}/setup.zsh\"
unfunction ${undef_args}
source \${(q)ZSH_ROS2_ROOT}/setup.zsh ||
{ echo 'Failed to load ros2 libraries!'; return }
(( \${#} == 0 )) && ${(q)exec} || ${(q)exec} \"\${@}\"
}"
done
unset exec def file defined undef_args