1414# See the License for the specific language governing permissions and
1515# limitations under the License.
1616#
17- # Authors: Manuel Muth, Denis Štogl
17+ # Authors: Manuel Muth, Denis Štogl, Atticus Russell
1818#
1919
2020# BEGIN: Stogl Robotics custom setup for nice colors and showing ROS workspace
@@ -62,12 +62,6 @@ function get_gitbranch {
6262 echo ` git branch --no-color 2> /dev/null | sed -e ' /^[^*]/d' -e ' s/* \(.*\)/\1/' `
6363}
6464
65- function parse_git_bracket {
66- if [[ " $( get_gitbranch) " != ' ' ]]; then
67- echo " <"
68- fi
69- }
70-
7165function set_git_color {
7266 if [[ " $( get_gitbranch) " != ' ' ]]; then
7367 # Get the status of the repo and chose a color accordingly
@@ -89,16 +83,6 @@ function set_git_color {
8983 fi
9084}
9185
92- function parse_git_branch_and_add_brackets {
93- gitbranch=" $( get_gitbranch) "
94-
95- if [[ " $gitbranch " != ' ' ]]; then
96- echo " <${gitbranch} "
97- # else
98- # echo "<no-git-branch"
99- fi
100- }
101-
10286function set_ros_workspace_color {
10387 if [[ -n ${ROS_WS} ]]; then
10488
@@ -119,16 +103,13 @@ function parse_ros_workspace {
119103 fi
120104}
121105
122- # Version mit time infront of values
123- # 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\] '
124106
125- # Version without git color
126- # 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\] '
127-
128- # Version with git color
129107# Start with an empty PS1
130108PS1=" "
131109
110+ # Add a newline character to move to the next line and visually separate from the previous terminal command
111+ PS1+=" \n"
112+
132113# Set the terminal title to the current ROS workspace
133114PS1+=" \[\e]0;\$ (parse_ros_workspace)\a\]"
134115
@@ -144,36 +125,46 @@ PS1+="\[${TERMINAL_COLOR_BROWN}\]\h"
144125# Add a yellow '-ssh-session' if SSH client is connected
145126PS1+=" \[${TERMINAL_COLOR_YELLOW} \]${text} "
146127
147- # Add a light gray ':'
148- PS1+=" \[${TERMINAL_COLOR_LIGHT_GRAY } \]: "
128+ # separate parts of header with a space with no highlighting
129+ PS1+=" \[${TERMINAL_COLOR_NC } \] "
149130
150131# Set the color of the ROS workspace
151132PS1+=" \[\$ (set_ros_workspace_color)\]"
152133
153134# Add the name of the ROS workspace
154135PS1+=" \$ (parse_ros_workspace)"
155136
156- # Set the color of the Git branch
157- PS1+=" \[${TERMINAL_COLOR_GREEN } \]\$ (parse_git_bracket) "
137+ # separate parts of header with a space with no highlighting
138+ PS1+=" \[${TERMINAL_COLOR_NC } \] "
158139
159- # Add the name of the Git branch
160- PS1+=" \[\$ (set_git_color)\]\$ (get_gitbranch)"
140+ # if in a git repo add the branch name in brackets
141+ # conditionals *in* the PS are needed so its evaluated each time the PS is printed
142+ PS1+=" \[\$ ([[ \$ (get_gitbranch) != '' ]] && echo -n \$ (set_git_color))\]"
143+ PS1+=" \$ (if [[ \$ (get_gitbranch) != '' ]]; then echo -n '<' && echo -n \$ (get_gitbranch) && echo -n '>'; fi)"
161144
162- # Add a green '>'
163- PS1+=" \[ ${TERMINAL_COLOR_GREEN} \]> "
145+ # Add a newline character to move to the next line
146+ PS1+=" \n "
164147
165148# Add the full file path relative to the user's home directory
166- # We can use the \w escape sequence to achieve this
167149PS1+=" \[${TERMINAL_COLOR_LIGHT_PURPLE} \]\w"
168150
169- # Add a newline character to move the prompt symbol to the next line
151+ # Add a newline character to move to the next line
170152PS1+=" \n"
171153
172- # Add the prompt symbol ('$') with a light purple color
173- PS1+=" \[${TERMINAL_COLOR_CYAN} \]\$ "
154+ # Add the time
155+ PS1+=" \[${TERMINAL_COLOR_NC} \]\D{%T}"
156+
157+ # separate parts of header with a space with no highlighting
158+ PS1+=" \[${TERMINAL_COLOR_NC} \] "
159+
160+ # Add the prompt symbol ('$')
161+ PS1+=" \[${TERMINAL_COLOR_NC} \]\$ "
162+
163+ # Add a space after the prompt symbol
164+ PS1+=" "
174165
175- # Reset the color and add a space
176- PS1+=" \[${TERMINAL_COLOR_NC} \]\[\e[m\] "
166+ # Reset the color
167+ PS1+=" \[${TERMINAL_COLOR_NC} \]\[\e[m\]"
177168
178169# Export the PS1 variable
179170export PS1
0 commit comments