Skip to content

Commit

Permalink
[jsk_tools] add rossetclient
Browse files Browse the repository at this point in the history
  • Loading branch information
sktometometo authored and knorth55 committed Jul 5, 2022
1 parent 1f5d027 commit 55578a4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion jsk_tools/env-hooks/99.jsk_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ' ')
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 55578a4

Please sign in to comment.