[ros-users] rosbash: roscd magic for cleaner title/prompt

Carlos Jaramillo ubuntuslave at gmail.com
Wed Feb 2 19:54:44 UTC 2011


Ivan and I added the following and seems to work fine now:

###########################################
# To enter ROSCD_MODE, type in roscd name_of_package
# To exit ROSCD_MODE, type in roscd
# If ROSCD_MODE is set, replaces the default bash prompt and tab title
# with [name_of_package].

export PS1_BAK=$PS1

PROMPT_COMMAND='
if [ "$ROSCD_MODE" ]; then
  basedir="${PWD#${PWD%%${ROSCD_MODE}*}}"
  if [ -z $basedir ]; then
      unset ROSCD_MODE
      export PS1=$PS1_BAK
        else
      export PS1="\[\e]0;[ ${ROSCD_MODE} ]\a\]\[\e[31;1m\][$basedir]:\$
\[\e[0m\]"
  fi
       else
  export PS1=$PS1_BAK
fi'

function roscd {
    local rosvals

    if [ -z $1 ]; then
      cd ${ROS_ROOT}
      unset ROSCD_MODE
      return 0
    fi

    _ros_decode_path $1 forceeval
    if [ $? != 0 ]; then
      echo "roscd: No such package '$1'"
      return 1
    elif [ -z $rosvals ]; then
      cd ${ROS_ROOT}
      return 0
    else
      cd ${rosvals[1]}${rosvals[2]}${rosvals[3]}
      export ROSCD_MODE=${rosvals[0]}
      return 0
    fi
}
#################################3

The fixes happened on
      basedir="${PWD#${PWD%%${ROSCD_MODE}*}}"
to keep track of subdirectory names where they are the same, such as in
rviz/src/rviz

And in the PROMPT_COMMAND part...

The above code should work fine now. Let us know if you still find problems.

Regards,

Carlos

On Wed, Feb 2, 2011 at 2:11 PM, Ivan Dryanovski
<ivan.dryanovski at gmail.com>wrote:

> Hi Radu,
>
> I tried running the same sequence of commands and it doesn't hang on
> my machine. But you are right that mixing roscd and cd creates
> problems. The scripting I did was a pretty quick hack into the roscd
> machine - there might be a more robust way to handle the switching.
>
> Ivan
>
> On Wed, Feb 2, 2011 at 1:57 PM, Radu Bogdan Rusu <rusu at willowgarage.com>
> wrote:
> > Not bad! :)
> >
> > The problem is... I bet most folks tend to mix-and-match roscd with cd.
> >
> > [:/opt/ros/unstable/ros]$ cd /tmp/
> > [:/tmp]$ roscd pcl
> > [pcl]:$ cd /
> > []:$ ls
> > ... hangs...  Cltr+C... nothing
> >
> >
> > Cheers,
> > Radu.
> > --
> > http://pointclouds.org
> >
> > On 02/02/2011 10:51 AM, Patrick Bouffard wrote:
> >> +1. Nice.
> >>
> >> Can this be put into diamondback (as a disabled-by-default option)?
> >>
> >> Pat
> >>
> >> On Wed, Feb 2, 2011 at 10:29 AM, Ivan Dryanovski
> >> <ivan.dryanovski at gmail.com>  wrote:
> >>> Hi everyone,
> >>>
> >>> My bash shell prompt and tab title normally look something like this:
> >>>
> >>> "idryanov at idryanov-desktop:~/ros/some-stack/foo$"
> >>>
> >>> I like to have several tabs opened, each one for a different package
> >>> I'm working on. I tweaked my rosbash file to manipulate the bash
> >>> prompt i get when working in ROS. So every time I type in `roscd foo`
> >>> (where foo is some package or stack) the tab title is replaced by
> >>> "[foo]" and my prompt is replaced by "[foo]:$ ". Further, if I then
> >>> type in `cd src`, the prompt is replaced by "[foo\src]". This makes it
> >>> much quicker to identify the working directory for each of the
> >>> (possibly many)  tabs I have open.
> >>>
> >>> When I type in `roscd`, the tab title and prompt revert to their
> >>> default system behavior (whatever it was prior to typing in `roscd
> >>> foo`).
> >>>
> >>> To play around with this, just replace the "function roscd" in
> >>> /ros/tools/rosbash with the code at the end of the email.
> >>>
> >>> Cheers,
> >>> Ivan
> >>>
> >>> ###########################################
> >>> # To enter ROSCD_MODE, type in roscd name_of_package
> >>> # To exit ROSCD_MODE, type in roscd
> >>> # If ROSCD_MODE is set, replaces the default bash prompt and tab title
> >>> # with [name_of_package].
> >>>
> >>> export PS1_BAK=$PS1
> >>>
> >>> PROMPT_COMMAND='
> >>> if [ "$ROSCD_MODE" ]; then
> >>>   basedir="${PWD#${PWD%${ROSCD_MODE}*}}"
> >>>   export PS1="\[\e]0;[ ${ROSCD_MODE} ]\a\]\[\e[31;1m\][$basedir]:\$
> \[\e[0m\]"
> >>>     else
> >>>   export PS1=$PS1_BAK
> >>> fi'
> >>>
> >>> function roscd {
> >>>     local rosvals
> >>>
> >>>     if [ -z $1 ]; then
> >>>       cd ${ROS_ROOT}
> >>>       unset ROSCD_MODE
> >>>       return 0
> >>>     fi
> >>>
> >>>     _ros_decode_path $1 forceeval
> >>>     if [ $? != 0 ]; then
> >>>       echo "roscd: No such package '$1'"
> >>>       return 1
> >>>     elif [ -z $rosvals ]; then
> >>>       cd ${ROS_ROOT}
> >>>       return 0
> >>>     else
> >>>       cd ${rosvals[1]}${rosvals[2]}${rosvals[3]}
> >>>       export ROSCD_MODE=${rosvals[0]}
> >>>       return 0
> >>>     fi
> >>> }
> >>>
> >>> _______________________________________________
> >>> ros-users mailing list
> >>> ros-users at code.ros.org
> >>> https://code.ros.org/mailman/listinfo/ros-users
> >>>
> >>>
> >> _______________________________________________
> >> ros-users mailing list
> >> ros-users at code.ros.org
> >> https://code.ros.org/mailman/listinfo/ros-users
> > _______________________________________________
> > ros-users mailing list
> > ros-users at code.ros.org
> > https://code.ros.org/mailman/listinfo/ros-users
> >
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20110202/415f5c28/attachment-0003.html>


More information about the ros-users mailing list