Commit 9a50ab72 authored by Johannes Bier's avatar Johannes Bier 💬
Browse files

setup should now work with bash and zsh

parent 8ab709b6
#!/bin/bash
if [[ "$_" == "$0" ]] ; then
#!/bin/sh
sourced=0
if [ -n "$ZSH_EVAL_CONTEXT" ]; then
case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
elif [ -n "$KSH_VERSION" ]; then
[ "$(cd $(dirname -- $0) && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) && pwd -P)/$(basename -- ${.sh.file})" ] && sourced=1
elif [ -n "$BASH_VERSION" ]; then
(return 0 2>/dev/null) && sourced=1
else # All other shells: examine $0 for known shell binary filenames
# Detects `sh` and `dash`; add additional shell filenames as needed.
case ${0##*/} in sh|dash) sourced=1;; esac
fi
if [[ "${sourced}" == 0 ]] ; then
echo "I'm not meant to be run - source me!"
exit 1
return 1
fi
if [[ ! -z "${ROS_DISTRO}" ]]; then
echo "ROS ${ROS_DISTRO} is already sourced!"
exit 1
return 1
fi
source /opt/ros/galactic/setup.bash
source /usr/share/colcon_cd/function/colcon_cd.sh
source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash
if [ -n "`$SHELL -c 'echo $ZSH_VERSION'`" ]; then
# assume Zsh
source /opt/ros/galactic/setup.zsh
source /usr/share/colcon_cd/function/colcon_cd.sh
source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.zsh
if test -f $(dirname "${(%):-%N}")/install/local_setup.zsh; then
source $(dirname "${(%):-%N}")/install/local_setup.zsh
else
printf "\n\033[0;33mWS is not built. Use 'cb'.\033[0m\n"
fi
elif [ -n "`$SHELL -c 'echo $BASH_VERSION'`" ]; then
# assume Bash
source /opt/ros/galactic/setup.bash
source /usr/share/colcon_cd/function/colcon_cd.sh
source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash
if test -f $(dirname "${BASH_SOURCE[0]}")/install/local_setup.bash; then
source $(dirname "${BASH_SOURCE[0]}")/install/local_setup.bash
else
printf "\n\033[0;33mWS is not built. Use 'cb'.\033[0m\n"
fi
else
# something else like fish
echo "It seems like you are not using bash or zsh. You are own your own."
return 1
fi
if [ -z "$1" ]; then
echo "Setup local ROS2 Env";
......@@ -29,22 +66,18 @@ else
fi
fi
if test -f $(dirname "${BASH_SOURCE[0]}")/install/local_setup.bash; then
source $(dirname "${BASH_SOURCE[0]}")/install/local_setup.bash
else
printf "\n\033[0;33mWS is not built. Use 'colcon build'.\033[0m\n"
fi
# shorthand for colcon build that works from anywhere
cb () {
pushd "$(dirname "$COLCON_PREFIX_PATH")"
# colcon build --symlink-install --packages-select cassiopeia_drive
PACKAGES="$1"
if [ -n "$PACKAGES" ]; then
PACKAGES="--packages-select ${PACKAGES}"
fi
colcon build --symlink-install --cmake-args -DBUILD_TESTING=0 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON $PACKAGES
popd
# TODO
# pushd doesn't push this if the current working dir is the same es the colcon ws dir
# so you will end up in the last dir you visited before using cb
pushd "$(dirname "$COLCON_PREFIX_PATH")"
PACKAGES="$1"
if [ -n "$PACKAGES" ]; then
PACKAGES="--packages-select ${PACKAGES}"
fi
colcon build --symlink-install --cmake-args -DBUILD_TESTING=0 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON $PACKAGES
popd
}
bold="$(tput sgr0)$(tput bold)"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment