50-prompt.sh (797B)
1 prompt_command() { 2 local prev_exit=$? 3 4 # Query cursor position (format: \e[<row>;<col>R) 5 printf "\e[6n" 6 read -rsd";" 7 read -rsdR PS1COL 8 9 PS1="" 10 [ "${PS1COL:-1}" -ne 1 ] && PS1+="\[\e[31;1m\]◆\[\e[m\]\n" # If current row is nonempty, add newline to PS1 11 PS1+="\[\e[36m\]\w\[\e[m\]" # Add working directory to PS1 12 if have git && git rev-parse --git-dir >/dev/null 2>&1; then # If in git repo... 13 PS1+=" \[\e[35m\] $(git branch --show-current)\[\e[m\]" # ...add branch name to PS1 14 fi 15 PS1+=" \[\e[31m\]$prev_exit\[\e[m\]" # Add previous exit code to PS1 16 PS1+="\n\[\e[32m\]▶\[\e[m\] " # Add actual prompt to PS1 17 } 18 19 export PROMPT_COMMAND=prompt_command 20 export PS2='\[\e[32m\]▷\[\e[m\] '