Skip to content
Snippets Groups Projects
Commit 19453246 authored by Montaño Sarria, Andres Felipe's avatar Montaño Sarria, Andres Felipe
Browse files

Improve if sentences

parent b5d72f5e
No related branches found
No related tags found
No related merge requests found
...@@ -41,9 +41,9 @@ function dockbuild(){ ...@@ -41,9 +41,9 @@ function dockbuild(){
key=$2 key=$2
if [[ $key = "--shell" ]]; then if [[ $key = "--shell" ]]; then
shell=$3 shell=$3
if [[ $shell = "zsh" ]]; then if [[ "${shell}" == "zsh" ]]; then
shell_path="/usr/bin/zsh" shell_path="/usr/bin/zsh"
elif [[ $shell = "bash" ]]; then elif [[ "${shell}" == "bash" ]]; then
shell_path="/bin/bash" shell_path="/bin/bash"
else else
echo "${RED}SHELL: ${shell} not supported${NC}" echo "${RED}SHELL: ${shell} not supported${NC}"
...@@ -97,7 +97,6 @@ function dockrun() { ...@@ -97,7 +97,6 @@ function dockrun() {
case $key in case $key in
--ws) --ws)
workspace="${HOME}/ros/${container_name}/$3" workspace="${HOME}/ros/${container_name}/$3"
export ROS_WORKSPACE=$workspace
shift shift
shift shift
;; ;;
...@@ -108,11 +107,11 @@ function dockrun() { ...@@ -108,11 +107,11 @@ function dockrun() {
;; ;;
--share) --share)
resource=$3 resource=$3
if [[ $resource = "video" ]]; then if [[ "${resource}" == "video" ]]; then
resource_to_share="--volume /dev/video0:/dev/video0" resource_to_share="--volume /dev/video0:/dev/video0"
elif [[ $resource = "pcan" ]]; then elif [[ "${resource}" == "pcan" ]]; then
resource_to_share="--volume /dev/pcanusb32:/dev/pcanusb32" resource_to_share="--volume /dev/pcanusb32:/dev/pcanusb32"
elif [[ $resource = "dev" ]]; then elif [[ "${resource}" == "dev" ]]; then
resource_to_share="--volume /dev:/dev" resource_to_share="--volume /dev:/dev"
fi fi
shift shift
...@@ -130,6 +129,8 @@ function dockrun() { ...@@ -130,6 +129,8 @@ function dockrun() {
esac esac
done done
export ROS_WORKSPACE=${workspace}
echo "${BLUE}Container name: ${container_name}" echo "${BLUE}Container name: ${container_name}"
echo "Workspace: ${workspace}" echo "Workspace: ${workspace}"
echo "Shell: ${docker_shell}" echo "Shell: ${docker_shell}"
......
...@@ -9,7 +9,7 @@ else ...@@ -9,7 +9,7 @@ else
fi fi
# Enable colcon tools # Enable colcon tools
if [[ "${ROS_VERSION}" = 2 ]]; then if [[ "${ROS_VERSION}" -eq 2 ]]; then
# Quick directory change # Quick directory change
if [[ -f "/usr/share/colcon_cd/function/colcon_cd.sh" ]]; then if [[ -f "/usr/share/colcon_cd/function/colcon_cd.sh" ]]; then
source /usr/share/colcon_cd/function/colcon_cd.sh source /usr/share/colcon_cd/function/colcon_cd.sh
...@@ -21,8 +21,8 @@ if [[ "${ROS_VERSION}" = 2 ]]; then ...@@ -21,8 +21,8 @@ if [[ "${ROS_VERSION}" = 2 ]]; then
fi fi
# Source rosmon # Source rosmon
function smon(){ function sourcerosmon(){
if [[ ${ROS_VERSION} = 1 ]]; then if [[ "${ROS_VERSION}" -eq 1 ]]; then
if [[ -f "/opt/ros/${ROS_DISTRO}/etc/catkin/profile.d/50-rosmon.${ext}" ]]; 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} source /opt/ros/${ROS_DISTRO}/etc/catkin/profile.d/50-rosmon.${ext}
else else
...@@ -33,23 +33,7 @@ function smon(){ ...@@ -33,23 +33,7 @@ function smon(){
# cd to the root of the workspace # cd to the root of the workspace
function roshome(){ function roshome(){
if [ "${ROS_VERSION}" = 1 ] cd ${ROS_HOME}
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
} }
# Source the current workspace # Source the current workspace
...@@ -59,7 +43,7 @@ function sourcews(){ ...@@ -59,7 +43,7 @@ function sourcews(){
ws_name=${cropped%%/*} ws_name=${cropped%%/*}
ws_path=${HOME}/ros/${ROS_DISTRO}/${ws_name} ws_path=${HOME}/ros/${ROS_DISTRO}/${ws_name}
if [ "${ROS_VERSION}" = 1 ] if [[ "${ROS_VERSION}" -eq 1 ]]
then then
FILE=${ws_path}/devel/setup.${ext} FILE=${ws_path}/devel/setup.${ext}
else else
...@@ -70,29 +54,29 @@ function sourcews(){ ...@@ -70,29 +54,29 @@ function sourcews(){
if [[ -f $FILE ]]; then if [[ -f $FILE ]]; then
cd ${ws_path} cd ${ws_path}
echo "${GREEN}Sourcing workspace: ${FILE}${NC}" echo "${GREEN}Sourcing workspace: ${FILE}${NC}"
source $FILE && smon source $FILE && sourcerosmon
cd ${current_dir} cd ${current_dir}
export ROS_HOME=${ws_path} export ROS_HOME=${ws_path}
else else
echo "${RED}Workspace not found: ${FILE}${NC}" echo "${RED}Workspace not found: ${FILE}${NC}"
export ROS_HOME=/opt/ros/${ROS_DISTRO}
fi fi
} }
# Source the current workspace # Source the current workspace
function sourceros(){ function sourceros(){
source /opt/ros/${ROS_DISTRO}/setup.${ext} source /opt/ros/${ROS_DISTRO}/setup.${ext}
export ROS_HOME="/opt/ros/${ROS_DISTRO}/"
# In ROS 1 source rosmon # In ROS 1 source rosmon
if [ "${ROS_VERSION}" = 1 ] if [[ "${ROS_VERSION}" -eq 1 ]]
then then
smon sourcerosmon
fi fi
} }
# Automatic catkin build # Automatic catkin build
function cb() { function cb() {
pwd_cb=$(pwd) pwd_cb=$(pwd)
if [ "${ROS_VERSION}" = 1 ] if [[ "${ROS_VERSION}" -eq 1 ]]
then then
roshome roshome
catkin build --summarize --cmake-args -DCMAKE_BUILD_TYPE=Release -- "$@" catkin build --summarize --cmake-args -DCMAKE_BUILD_TYPE=Release -- "$@"
...@@ -106,7 +90,7 @@ function cb() { ...@@ -106,7 +90,7 @@ function cb() {
# Clean workspace (delete the generated folders, then catkin build) # Clean workspace (delete the generated folders, then catkin build)
function cbclean(){ function cbclean(){
if [ "${ROS_VERSION}" = 1 ] if [[ "${ROS_VERSION}" -eq 1 ]]
then then
roshome && rm -rf build devel install && catkin build --summarize --cmake-args -DCMAKE_BUILD_TYPE=Release roshome && rm -rf build devel install && catkin build --summarize --cmake-args -DCMAKE_BUILD_TYPE=Release
else else
...@@ -136,7 +120,7 @@ alias sc=sourcews ...@@ -136,7 +120,7 @@ alias sc=sourcews
# Check if ROS_DISTRO is set. # Check if ROS_DISTRO is set.
if [[ -z "${ROS_DISTRO}" ]]; then if [[ -z "${ROS_DISTRO}" ]]; then
ROS_DIR=/opt/ros ROS_DIR=/opt/ros
if [ -d "$ROS_DIR" ]; if [ -d "${ROS_DIR}" ];
then then
export ROS_DISTRO=$(basename $(find /opt/ros/* -maxdepth 0 -type d | head -1)) export ROS_DISTRO=$(basename $(find /opt/ros/* -maxdepth 0 -type d | head -1))
#echo "ROS_DISTRO set to ${ROS_DISTRO}" #echo "ROS_DISTRO set to ${ROS_DISTRO}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment