Skip to content

Commit ffd526e

Browse files
sktometometoknorth55
authored andcommitted
[jsk_tools] add rossetclient
1 parent 1e741fa commit ffd526e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

jsk_tools/env-hooks/99.jsk_tools.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ _update_prompt() {
4444
export PS1="${WITHOUT_ROS_PROMPT}"
4545
fi
4646
elif [ "$master_host" != "" ]; then
47-
local ros_prompt="[$ROS_MASTER_URI][$ROS_IP]"
47+
if [[ "$ROS_HOSTNAME" != "" && "$ROS_IP" == "" ]]; then
48+
local ros_prompt="[$ROS_MASTER_URI][$ROS_HOSTNAME]"
49+
else
50+
local ros_prompt="[$ROS_MASTER_URI][$ROS_IP]"
51+
fi
4852
if [ "$CATKIN_SHELL" = "bash" ]; then
4953
export PS1="\[\033[00;31m\]$ros_prompt\[\033[00m\] ${WITHOUT_ROS_PROMPT}"
5054
elif [ "$CATKIN_SHELL" = "zsh" ]; then
@@ -86,6 +90,7 @@ rossetip_dev() {
8690

8791
rossetip_addr() {
8892
local target_host=${1-"133.11.216.211"}
93+
echo "target_host: $target_host"
8994
# Check if target_host looks like ip address or not
9095
if [ "$(echo $target_host | sed -e 's/[0-9\.]//g')" != "" ]; then
9196
target_host_ip=$(timeout 0.01 getent hosts ${target_host} | cut -f 1 -d ' ')
@@ -125,6 +130,24 @@ rossetip() {
125130
fi
126131
}
127132

133+
rossetclient() {
134+
local client_interface=$1
135+
if [[ $client_interface =~ [0-9]+.[0-9]+.[0-9]+.[0-9]+ ]]; then
136+
export ROS_IP="$client_interface"
137+
else
138+
local addr_if_client_is_device=${LANC=C ip -o -4 a | grep lo\ \ \ | cut -d\ -f7 | cut -d\/ -f1}
139+
if [[ $addr_if_client_is_device = "" ]]; then
140+
export ROS_IP="$addr_if_client_is_device"
141+
else
142+
export ROS_HOSTNAME="$client_interface"
143+
fi
144+
fi
145+
echo -e "\e[1;31mset ROS_IP to \"$ROS_IP\" and ROS_HOSTNAME to \"$ROS_HOSTNAME\"\e[m"
146+
if [ "$NO_ROS_PROMPT" = "" ]; then
147+
_update_prompt
148+
fi
149+
}
150+
128151
rosn() {
129152
if [ "$1" = "" ]; then
130153
select=$(rosnode list | percol | xargs -n 1 rosnode info | percol)

0 commit comments

Comments
 (0)