[ros-users] rosbash: roscd magic for cleaner title/prompt
Patrick Bouffard
bouffard at eecs.berkeley.edu
Wed Feb 2 18:51:34 UTC 2011
+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
>
>
More information about the ros-users
mailing list