From b85772067dd13161e856594b5179f2f75de9b3b1 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Mon, 10 Feb 2025 23:26:27 -0800 Subject: [PATCH] Add init file timings and lazy load ros2 stuff --- init.zsh | 16 +++++++++++++++- lazy-ros2.zsh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 lazy-ros2.zsh diff --git a/init.zsh b/init.zsh index ff9d33f..837d368 100644 --- a/init.zsh +++ b/init.zsh @@ -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 ))" +} diff --git a/lazy-ros2.zsh b/lazy-ros2.zsh new file mode 100644 index 0000000..f1d1eab --- /dev/null +++ b/lazy-ros2.zsh @@ -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