From b1ab7a74a3a930d3874ce5d7055fbeb6675cfbbb Mon Sep 17 00:00:00 2001 From: Atticus Russell Date: Wed, 24 May 2023 18:32:39 -0400 Subject: [PATCH 1/2] split apart PS1, added full path, $ on newline --- scripts/configuration/terminal_coloring.bash | 52 +++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/scripts/configuration/terminal_coloring.bash b/scripts/configuration/terminal_coloring.bash index 1c0aaba0..675b5f73 100644 --- a/scripts/configuration/terminal_coloring.bash +++ b/scripts/configuration/terminal_coloring.bash @@ -126,7 +126,57 @@ function parse_ros_workspace { # 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\] ' # 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\] ' +# Start with an empty PS1 +PS1="" + +# 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}" + +# Add a light gray ':' +PS1+="\[${TERMINAL_COLOR_LIGHT_GRAY}\]:" + +# Set the color of the ROS workspace +PS1+="\[\$(set_ros_workspace_color)\]" + +# Add the name of the ROS workspace +PS1+="\$(parse_ros_workspace)" + +# Set the color of the Git branch +PS1+="\[${TERMINAL_COLOR_GREEN}\]\$(parse_git_bracket)" + +# Add the name of the Git branch +PS1+="\[\$(set_git_color)\]\$(get_gitbranch)" + +# Add a green '>' +PS1+="\[${TERMINAL_COLOR_GREEN}\]>" + +# Add the full file path relative to the user's home directory +# We can use the \w escape sequence to achieve this +PS1+="\[${TERMINAL_COLOR_LIGHT_PURPLE}\]\w" + +# Add a newline character to move the prompt symbol to the next line +PS1+="\n" + +# Add the prompt symbol ('$') with a light purple color +PS1+="\[${TERMINAL_COLOR_CYAN}\]\$" + +# Reset the color and add a space +PS1+="\[${TERMINAL_COLOR_NC}\]\[\e[m\] " + +# Export the PS1 variable +export PS1 # END: Stogl Robotics custom setup for nice colors and showing ROS workspace From f280cc76076473fd464cf529321af5dbe411a486 Mon Sep 17 00:00:00 2001 From: Atticus Russell Date: Thu, 25 May 2023 15:23:29 -0400 Subject: [PATCH 2/2] created multi-line promptstring --- scripts/configuration/terminal_coloring.bash | 65 +++++++++----------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/scripts/configuration/terminal_coloring.bash b/scripts/configuration/terminal_coloring.bash index 675b5f73..187b49f3 100644 --- a/scripts/configuration/terminal_coloring.bash +++ b/scripts/configuration/terminal_coloring.bash @@ -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 @@ -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 @@ -89,16 +83,6 @@ function set_git_color { fi } -function parse_git_branch_and_add_brackets { - gitbranch="$(get_gitbranch)" - - if [[ "$gitbranch" != '' ]]; then - echo "<${gitbranch}" -# else -# echo "\['"\[${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\] ' - -# Version with git color # 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\]" @@ -144,8 +125,8 @@ PS1+="\[${TERMINAL_COLOR_BROWN}\]\h" # Add a yellow '-ssh-session' if SSH client is connected PS1+="\[${TERMINAL_COLOR_YELLOW}\]${text}" -# Add a light gray ':' -PS1+="\[${TERMINAL_COLOR_LIGHT_GRAY}\]:" +# 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)\]" @@ -153,27 +134,37 @@ PS1+="\[\$(set_ros_workspace_color)\]" # Add the name of the ROS workspace PS1+="\$(parse_ros_workspace)" -# Set the color of the Git branch -PS1+="\[${TERMINAL_COLOR_GREEN}\]\$(parse_git_bracket)" +# separate parts of header with a space with no highlighting +PS1+="\[${TERMINAL_COLOR_NC}\] " -# Add the name of the Git branch -PS1+="\[\$(set_git_color)\]\$(get_gitbranch)" +# 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 green '>' -PS1+="\[${TERMINAL_COLOR_GREEN}\]>" +# Add a newline character to move to the next line +PS1+="\n" # Add the full file path relative to the user's home directory -# We can use the \w escape sequence to achieve this PS1+="\[${TERMINAL_COLOR_LIGHT_PURPLE}\]\w" -# Add a newline character to move the prompt symbol to the next line +# Add a newline character to move to the next line PS1+="\n" -# Add the prompt symbol ('$') with a light purple color -PS1+="\[${TERMINAL_COLOR_CYAN}\]\$" +# 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 and add a space -PS1+="\[${TERMINAL_COLOR_NC}\]\[\e[m\] " +# Reset the color +PS1+="\[${TERMINAL_COLOR_NC}\]\[\e[m\]" # Export the PS1 variable export PS1