User Tools

Site Tools


programming:bash_notes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

programming:bash_notes [2022/06/10 19:19] – external edit 127.0.0.1programming:bash_notes [2022/11/04 20:27] (current) – colored prompt with git branch rene
Line 8: Line 8:
 <code> <code>
 for f in *; do mv -i "$f" "${f//[\"<>:\*\|\/\?[:space:]]}"; done for f in *; do mv -i "$f" "${f//[\"<>:\*\|\/\?[:space:]]}"; done
 +</code>
 +
 +=== Colored prompt ===
 +Have a colored prompt for the user spanning two lines.
 +
 +  * date and time in white
 +  * Path in blue color
 +  * branch in yellow
 +  * username and server in green
 +  * command in white
 +
 +<code>
 +[2022-11-04 20:09.15] ~
 +(master)[user@server]:
 +</code>
 +
 +The function fetches the branch name and the prompt dispays it. 
 +<code bash>
 +parse_git_branch() {
 +     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
 +}
 +</code>
 +
 +<code bash>
 +export PS1="\n[\\D{%Y-%m-%d %H:%M.%S}] \[\033[01;34m\]\w\[\033[00m\]\n\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\[\033[01;32m\][\u@\h]\[\033[00m\]: \$ "
 +</code>
 +
 +For the root user maybe a red color for the username and server is better
 +
 +<code bash>
 +export PS1="\n[\\D{%Y-%m-%d %H:%M.%S}] \[\033[01;34m\]\w\[\033[00m\]\n\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\[\033[01;31m\][\u@\h]\[\033[00m\]: \$ "
 </code> </code>
  
programming/bash_notes.txt · Last modified: 2022/11/04 20:27 by rene