Skip to content

Instantly share code, notes, and snippets.

@NathanaelGandhi
Last active June 4, 2024 00:38
Show Gist options
  • Save NathanaelGandhi/f69655f230b9b760e115856c748fe4c3 to your computer and use it in GitHub Desktop.
Save NathanaelGandhi/f69655f230b9b760e115856c748fe4c3 to your computer and use it in GitHub Desktop.
setup aliases for sourcing ROS2 (POSIX-compliant script)
#!/bin/sh
# Define the shell rc (ie. ~/.bashrc or ~/.zshrc)
SHELL_RC="${HOME}/.$(basename ${SHELL})rc"
# Check if SHELL_RC exists, if not, use .profile
if [ ! -f "${SHELL_RC}" ]; then
echo "${SHELL_RC} not found"
SHELL_RC="$HOME/.profile"
fi
# Add sr alias to the selected shell rc file
if ! grep -q 'alias sr=' "${SHELL_RC}"; then
echo 'alias sr="[ -f \"/opt/ros/humble/setup.$(basename $SHELL)\" ] && source \"/opt/ros/humble/setup.$(basename $SHELL)\" || echo \"/opt/ros/humble/setup.$(basename $SHELL) does not exist.\""' >> "${SHELL_RC}"
echo "alias sr has been added to ${SHELL_RC}"
else
echo "alias sr already exists in ${SHELL_RC}"
fi
# Add sc alias to the selected shell rc file
if ! grep -q 'alias sc=' "${SHELL_RC}"; then
echo 'alias sc="[ -f \"install/setup.$(basename $SHELL)\" ] && source \"install/setup.$(basename $SHELL)\" || echo \"install/setup.$(basename $SHELL) does not exist.\""' >> "${SHELL_RC}"
echo "alias sc has been added to ${SHELL_RC}"
else
echo "alias sc already exists in ${SHELL_RC}"
fi
# Add slc alias to the selected shell rc file
if ! grep -q 'alias slc=' "${SHELL_RC}"; then
echo 'alias slc="[ -f \"install/local_setup.$(basename $SHELL)\" ] && source \"install/local_setup.$(basename $SHELL)\" || echo \"install/local_setup.$(basename $SHELL) does not exist.\""' >> "${SHELL_RC}"
echo "alias slc has been added to ${SHELL_RC}"
else
echo "alias slc already exists in ${SHELL_RC}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment