31 lines
1.0 KiB
Bash
31 lines
1.0 KiB
Bash
|
RST='\e[0m'
|
||
|
PS1_LINE=`printf -- '- %.0s' {1..200}` # Background lines
|
||
|
|
||
|
update() {
|
||
|
# Exit code
|
||
|
# [ $? == 0 ] && PS1_STATUS="" || PS1_STATUS=""
|
||
|
# [ $? == 0 ] && PS1_STATUS="\e[38;5;113m${RST}" || PS1_STATUS="\e[38;5;167m${RST}"
|
||
|
|
||
|
PS1_FILL=${PS1_LINE:0:$COLUMNS} # Background fill
|
||
|
|
||
|
FREE_RAM=$(free | awk '/Mem/{printf("%2d%"), $3/$2*100}')
|
||
|
|
||
|
# Git branch
|
||
|
GIT_BRANCH=''
|
||
|
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
|
||
|
GIT_BRANCH="[git ${ref#refs/heads/}] "
|
||
|
}
|
||
|
|
||
|
PROMPT_COMMAND=update
|
||
|
|
||
|
PS1_HOST="\e[38;5;159m \h${RST}" # Host
|
||
|
PS1_CLOCK="\e[38;5;227m \t${RST}" # Clock
|
||
|
PS1_USER="\e[38;5;218m \u${RST}" # User
|
||
|
PS1_RAM="\e[38;5;113m \$FREE_RAM${RST}" # RAM
|
||
|
PS1_FOLDER="\e[38;5;215m \W${RST}" # Folder
|
||
|
PS1_GIT="\e[38;5;215m\$GIT_BRANCH${RST}" # Git branch (if exist)
|
||
|
|
||
|
PS1="\e[0;90m\${PS1_FILL}\[\033[0G\]${PS1_HOST} ${PS1_USER} ${PS1_FOLDER} \
|
||
|
\[\033[\$((COLUMNS-17))G\] ${PS1_RAM} ${PS1_CLOCK}${RST}\n${PS1_GIT}\
|
||
|
(\e[38;5;113m\$(if [ \$? == 0 ]; then echo ''; else echo ''; fi)${RST})> "
|