From 3ceef9dfaa5b3507808bf28b20f01099c262fb9d Mon Sep 17 00:00:00 2001 From: Koki Shinjo Date: Tue, 28 Jun 2022 22:36:55 +0900 Subject: [PATCH] [jsk_tools] add rossetclient --- jsk_tools/env-hooks/99.jsk_tools.sh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/jsk_tools/env-hooks/99.jsk_tools.sh b/jsk_tools/env-hooks/99.jsk_tools.sh index 56334e784..c3dc26a8a 100644 --- a/jsk_tools/env-hooks/99.jsk_tools.sh +++ b/jsk_tools/env-hooks/99.jsk_tools.sh @@ -44,7 +44,11 @@ _update_prompt() { export PS1="${WITHOUT_ROS_PROMPT}" fi elif [ "$master_host" != "" ]; then - local ros_prompt="[$ROS_MASTER_URI][$ROS_IP]" + if [[ "$ROS_HOSTNAME" != "" && "$ROS_IP" == "" ]]; then + local ros_prompt="[$ROS_MASTER_URI][$ROS_HOSTNAME]" + else + local ros_prompt="[$ROS_MASTER_URI][$ROS_IP]" + fi if [ "$CATKIN_SHELL" = "bash" ]; then export PS1="\[\033[00;31m\]$ros_prompt\[\033[00m\] ${WITHOUT_ROS_PROMPT}" elif [ "$CATKIN_SHELL" = "zsh" ]; then @@ -86,6 +90,7 @@ rossetip_dev() { rossetip_addr() { local target_host=${1-"133.11.216.211"} + echo "target_host: $target_host" # Check if target_host looks like ip address or not if [ "$(echo $target_host | sed -e 's/[0-9\.]//g')" != "" ]; then target_host_ip=$(timeout 0.01 getent hosts ${target_host} | cut -f 1 -d ' ') @@ -125,6 +130,24 @@ rossetip() { fi } +rossetclient() { + local client_interface=$1 + if [[ $client_interface =~ [0-9]+.[0-9]+.[0-9]+.[0-9]+ ]]; then + export ROS_IP="$client_interface" + else + local addr_if_client_is_device=${LANC=C ip -o -4 a | grep lo\ \ \ | cut -d\ -f7 | cut -d\/ -f1} + if [[ $addr_if_client_is_device = "" ]]; then + export ROS_IP="$addr_if_client_is_device" + else + export ROS_HOSTNAME="$client_interface" + fi + fi + echo -e "\e[1;31mset ROS_IP to \"$ROS_IP\" and ROS_HOSTNAME to \"$ROS_HOSTNAME\"\e[m" + if [ "$NO_ROS_PROMPT" = "" ]; then + _update_prompt + fi +} + rosn() { if [ "$1" = "" ]; then select=$(rosnode list | percol | xargs -n 1 rosnode info | percol)