Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsk_tools] add rossetclient #19

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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