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

Add RTW “header” to terminal with all data #134

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
87 changes: 64 additions & 23 deletions scripts/configuration/terminal_coloring.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Authors: Manuel Muth, Denis Štogl
# Authors: Manuel Muth, Denis Štogl, Atticus Russell
#

# BEGIN: Stogl Robotics custom setup for nice colors and showing ROS workspace
Expand Down Expand Up @@ -62,12 +62,6 @@ function get_gitbranch {
echo `git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
}

function parse_git_bracket {
if [[ "$(get_gitbranch)" != '' ]]; then
echo "<"
fi
}

function set_git_color {
if [[ "$(get_gitbranch)" != '' ]]; then
# Get the status of the repo and chose a color accordingly
Expand All @@ -90,16 +84,6 @@ function set_git_color {
fi
}

function parse_git_branch_and_add_brackets {
gitbranch="$(get_gitbranch)"

if [[ "$gitbranch" != '' ]]; then
echo "<${gitbranch}"
# else
# echo "<no-git-branch"
fi
}

function set_ros_workspace_color {
if [[ -n ${ROS_WS} ]]; then

Expand All @@ -120,14 +104,71 @@ function parse_ros_workspace {
fi
}

# Version mit time infront of values
# export PS1="\[\e]0;"'$(parse_ros_workspace)'"\a\]\[${TERMINAL_COLOR_LIGHT_GRAY}\]"'[\t]\['"\[${TERMINAL_COLOR_LIGHT_GREEN}\]"'\u\['"\[${TERMINAL_COLOR_LIGHT_GRAY}\]"'@\['"\[${TERMINAL_COLOR_BROWN}\]"'\h\['"\[${TERMINAL_COLOR_YELLOW}\]"'${text}\['"\[${TERMINAL_COLOR_LIGHT_GRAY}\]"':'"\["'$(set_ros_workspace_color)'"\]"'$(parse_ros_workspace)\['"\[${TERMINAL_COLOR_GREEN}\]"'$(parse_git_branch_and_add_brackets)>\['"\[${TERMINAL_COLOR_LIGHT_PURPLE}\]"'\W\['"\[${TERMINAL_COLOR_LIGHT_PURPLE}\]"'$\['"\[${TERMINAL_COLOR_NC}\]"'\[\e[m\] '

# Version without git color
# export PS1="\[\e]0;"'$(parse_ros_workspace)'"\a\]\[${TERMINAL_COLOR_LIGHT_GREEN}\]"'\u\['"\[${TERMINAL_COLOR_LIGHT_GRAY}\]"'@\['"\[${TERMINAL_COLOR_BROWN}\]"'\h\['"\[${TERMINAL_COLOR_YELLOW}\]"'${text}\['"\[${TERMINAL_COLOR_LIGHT_GRAY}\]"':'"\["'$(set_ros_workspace_color)'"\]"'$(parse_ros_workspace)\['"\[${TERMINAL_COLOR_GREEN}\]"'$(parse_git_branch_and_add_brackets)>\['"\[${TERMINAL_COLOR_LIGHT_PURPLE}\]"'\W\['"\[${TERMINAL_COLOR_LIGHT_PURPLE}\]"'$\['"\[${TERMINAL_COLOR_NC}\]"'\[\e[m\] '
# Start with an empty PS1
PS1=""

# Add a newline character to move to the next line and visually separate from the previous terminal command
PS1+="\n"

# Set the terminal title to the current ROS workspace
PS1+="\[\e]0;\$(parse_ros_workspace)\a\]"

# Set the user text color to light green
PS1+="\[${TERMINAL_COLOR_LIGHT_GREEN}\]\u"

# Add a light gray '@'
PS1+="\[${TERMINAL_COLOR_LIGHT_GRAY}\]@"

# Set the host name color to brown
PS1+="\[${TERMINAL_COLOR_BROWN}\]\h"

# Add a yellow '-ssh-session' if SSH client is connected
PS1+="\[${TERMINAL_COLOR_YELLOW}\]${text}"

# separate parts of header with a space with no highlighting
PS1+="\[${TERMINAL_COLOR_NC}\] "

# Set the color of the ROS workspace
PS1+="\[\$(set_ros_workspace_color)\]"

# Add the name of the ROS workspace
PS1+="\$(parse_ros_workspace)"

# separate parts of header with a space with no highlighting
PS1+="\[${TERMINAL_COLOR_NC}\] "

# if in a git repo add the branch name in brackets
# conditionals *in* the PS are needed so its evaluated each time the PS is printed
PS1+="\[\$([[ \$(get_gitbranch) != '' ]] && echo -n \$(set_git_color))\]"
PS1+="\$(if [[ \$(get_gitbranch) != '' ]]; then echo -n '<' && echo -n \$(get_gitbranch) && echo -n '>'; fi)"

# Add a newline character to move to the next line
PS1+="\n"

# Add the full file path relative to the user's home directory
PS1+="\[${TERMINAL_COLOR_LIGHT_PURPLE}\]\w"

# Add a newline character to move to the next line
PS1+="\n"

# Add the time
PS1+="\[${TERMINAL_COLOR_NC}\]\D{%T}"

# separate parts of header with a space with no highlighting
PS1+="\[${TERMINAL_COLOR_NC}\] "

# Add the prompt symbol ('$')
PS1+="\[${TERMINAL_COLOR_NC}\]\$"

# Add a space after the prompt symbol
PS1+=" "

# Reset the color
PS1+="\[${TERMINAL_COLOR_NC}\]\[\e[m\]"

# Version with git color
export PS1="\[\e]0;"'$(parse_ros_workspace)'"\a\]\[${TERMINAL_COLOR_LIGHT_GREEN}\]"'\u\['"\[${TERMINAL_COLOR_LIGHT_GRAY}\]"'@\['"\[${TERMINAL_COLOR_BROWN}\]"'\h\['"\[${TERMINAL_COLOR_YELLOW}\]"'${text}\['"\[${TERMINAL_COLOR_LIGHT_GRAY}\]"':'"\["'$(set_ros_workspace_color)'"\]"'$(parse_ros_workspace)\['"\[${TERMINAL_COLOR_GREEN}\]"'$(parse_git_bracket)'"\["'$(set_git_color)'"\]"'$(get_gitbranch)'"\[${TERMINAL_COLOR_GREEN}\]"'>'"\[${TERMINAL_COLOR_LIGHT_PURPLE}\]"'\W\['"\[${TERMINAL_COLOR_LIGHT_PURPLE}\]"'$\['"\[${TERMINAL_COLOR_NC}\]"'\[\e[m\] '
# Export the PS1 variable
export PS1


# END: Stogl Robotics custom setup for nice colors and showing ROS workspace