diff --git a/dotfiles/docker.sh b/dotfiles/docker.sh index 21fa0c17ab9ba920e9d3d532ae296e742158d7a8..3d9cb21e42bd4ade47881529f480380ce9113862 100644 --- a/dotfiles/docker.sh +++ b/dotfiles/docker.sh @@ -41,9 +41,9 @@ function dockbuild(){ key=$2 if [[ $key = "--shell" ]]; then shell=$3 - if [[ $shell = "zsh" ]]; then + if [[ "${shell}" == "zsh" ]]; then shell_path="/usr/bin/zsh" - elif [[ $shell = "bash" ]]; then + elif [[ "${shell}" == "bash" ]]; then shell_path="/bin/bash" else echo "${RED}SHELL: ${shell} not supported${NC}" @@ -97,7 +97,6 @@ function dockrun() { case $key in --ws) workspace="${HOME}/ros/${container_name}/$3" - export ROS_WORKSPACE=$workspace shift shift ;; @@ -108,11 +107,11 @@ function dockrun() { ;; --share) resource=$3 - if [[ $resource = "video" ]]; then + if [[ "${resource}" == "video" ]]; then resource_to_share="--volume /dev/video0:/dev/video0" - elif [[ $resource = "pcan" ]]; then + elif [[ "${resource}" == "pcan" ]]; then resource_to_share="--volume /dev/pcanusb32:/dev/pcanusb32" - elif [[ $resource = "dev" ]]; then + elif [[ "${resource}" == "dev" ]]; then resource_to_share="--volume /dev:/dev" fi shift @@ -130,6 +129,8 @@ function dockrun() { esac done + export ROS_WORKSPACE=${workspace} + echo "${BLUE}Container name: ${container_name}" echo "Workspace: ${workspace}" echo "Shell: ${docker_shell}" diff --git a/dotfiles/ros.sh b/dotfiles/ros.sh index 78dee100862083e70974c98e1c0c81e328f4f5c1..5b387875ff0f3fa3edbede3bad757090d152d628 100644 --- a/dotfiles/ros.sh +++ b/dotfiles/ros.sh @@ -9,7 +9,7 @@ else fi # Enable colcon tools -if [[ "${ROS_VERSION}" = 2 ]]; then +if [[ "${ROS_VERSION}" -eq 2 ]]; then # Quick directory change if [[ -f "/usr/share/colcon_cd/function/colcon_cd.sh" ]]; then source /usr/share/colcon_cd/function/colcon_cd.sh @@ -21,8 +21,8 @@ if [[ "${ROS_VERSION}" = 2 ]]; then fi # Source rosmon -function smon(){ - if [[ ${ROS_VERSION} = 1 ]]; then +function sourcerosmon(){ + if [[ "${ROS_VERSION}" -eq 1 ]]; then if [[ -f "/opt/ros/${ROS_DISTRO}/etc/catkin/profile.d/50-rosmon.${ext}" ]]; then source /opt/ros/${ROS_DISTRO}/etc/catkin/profile.d/50-rosmon.${ext} else @@ -33,23 +33,7 @@ function smon(){ # cd to the root of the workspace function roshome(){ - if [ "${ROS_VERSION}" = 1 ] - then - if command -v roscd &> /dev/null - then - roscd && cd .. - export ROS_HOME=$(pwd) - else - echo "command ** roscd ** not found" - fi - else - if command -v colcon_cd &> /dev/null - then - colcon_cd - else - echo "command ** colcon_cd ** not found" - fi - fi + cd ${ROS_HOME} } # Source the current workspace @@ -59,7 +43,7 @@ function sourcews(){ ws_name=${cropped%%/*} ws_path=${HOME}/ros/${ROS_DISTRO}/${ws_name} - if [ "${ROS_VERSION}" = 1 ] + if [[ "${ROS_VERSION}" -eq 1 ]] then FILE=${ws_path}/devel/setup.${ext} else @@ -70,29 +54,29 @@ function sourcews(){ if [[ -f $FILE ]]; then cd ${ws_path} echo "${GREEN}Sourcing workspace: ${FILE}${NC}" - source $FILE && smon + source $FILE && sourcerosmon cd ${current_dir} export ROS_HOME=${ws_path} else echo "${RED}Workspace not found: ${FILE}${NC}" + export ROS_HOME=/opt/ros/${ROS_DISTRO} fi } # Source the current workspace function sourceros(){ source /opt/ros/${ROS_DISTRO}/setup.${ext} - export ROS_HOME="/opt/ros/${ROS_DISTRO}/" # In ROS 1 source rosmon - if [ "${ROS_VERSION}" = 1 ] + if [[ "${ROS_VERSION}" -eq 1 ]] then - smon + sourcerosmon fi } # Automatic catkin build function cb() { pwd_cb=$(pwd) - if [ "${ROS_VERSION}" = 1 ] + if [[ "${ROS_VERSION}" -eq 1 ]] then roshome catkin build --summarize --cmake-args -DCMAKE_BUILD_TYPE=Release -- "$@" @@ -106,7 +90,7 @@ function cb() { # Clean workspace (delete the generated folders, then catkin build) function cbclean(){ - if [ "${ROS_VERSION}" = 1 ] + if [[ "${ROS_VERSION}" -eq 1 ]] then roshome && rm -rf build devel install && catkin build --summarize --cmake-args -DCMAKE_BUILD_TYPE=Release else @@ -136,7 +120,7 @@ alias sc=sourcews # Check if ROS_DISTRO is set. if [[ -z "${ROS_DISTRO}" ]]; then ROS_DIR=/opt/ros - if [ -d "$ROS_DIR" ]; + if [ -d "${ROS_DIR}" ]; then export ROS_DISTRO=$(basename $(find /opt/ros/* -maxdepth 0 -type d | head -1)) #echo "ROS_DISTRO set to ${ROS_DISTRO}"