User Tools

Site Tools


programming:bash_notes

Remove character from filenames

To remove the charachters “ < > : * | ? from filenames in the current folder (especially handy when files need to be placed on onedrive/windows share)

for f in *; do mv -i "$f" "${f//[\"<>:\*\|\/\?]}"; done

It's also possible to remove all spaces in filenames by including [:space:] in the string.

for f in *; do mv -i "$f" "${f//[\"<>:\*\|\/\?[:space:]]}"; done

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
[2022-11-04 20:09.15] ~
(master)[user@server]: $ 

The function fetches the branch name and the prompt dispays it.

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
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\]: \$ "

For the root user maybe a red color for the username and server is better

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\]: \$ "
programming/bash_notes.txt · Last modified: 2022/11/04 20:27 by rene