Prompt string in a terminal

Prompt string

This string is what that usually appears on a terminal






This string can be made better by updating the 'PS1' enviroment variable. I'm using the below value in my 'PS1' variable.
 PS1='\[`if [ $? = 0 ]; then printf "\033[1;92m"; else printf "\033[1;91m"; fi`\]\h\[\033[0m\]:\[\033[01;34m\]$(p="${PWD#${HOME}}"; [ "${PWD}" != "${p}" ] && printf "~";IFS=/; for q in ${p:1}; do printf /${q:0:1}; done; printf "${q:1}")\[\033[00m\]\$ '  

With this value, you can see a better prompt string

  • Only the hostname appears
  • The hostname appears in green if the previous command return value is '0' else, it appears in red
  • Only the current directory appears with the full name, while the parent directories, are abbrevated to their first letter
If you like this prompt string, you can update in your .bashrc file. Please refer this link for more info.

Comments

Popular Posts