zsh-config/lazy-ros2.zsh

38 lines
861 B
Bash
Raw Permalink Normal View History

# Lazy-load ros2 stuff
2025-02-15 22:41:04 -08:00
(( ${+ZSH_ROS2_ROOT} )) || return
2025-02-17 00:13:11 -08:00
# Define as a function so it can be overridden for speed
function zsh-load-ros2() {
source "${ZSH_ROS2_ROOT}/setup.zsh"
}
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}
2025-02-17 00:13:11 -08:00
zsh-load-ros2 ||
{ echo 'Failed to load ros2 libraries!'; return }
(( \${#} == 0 )) && ${(q)exec} || ${(q)exec} \"\${@}\"
}"
done
unset exec def file defined undef_args