Skip to content
Snippets Groups Projects
Commit 622c0af6 authored by oli10's avatar oli10
Browse files

script added

parent e75d22fb
Branches main
No related merge requests found
#!/bin/bash
# binary tput output is converted into string
function tput_to_str() {
TPUT=$(tput $@)
OUT=""
for (( i = 0; i < ${#TPUT}; i++ )); do
local CH=${TPUT:$i:1}
if [[ "${CH}" < " " ]]; then
printf -v CH "\\%03o" "'${CH}"
fi
OUT+=$CH
done
echo $OUT
}
function prompt() {
#see man terminfo
PS_COLOR_BLACK=0
PS_COLOR_RED=1
PS_COLOR_GREEN=2
PS_COLOR_BROWN=3
PS_COLOR_BLUE=4
PS_COLOR_MAGENTA=5
PS_COLOR_CYAN=6
PS_COLOR_LGRAY=7
PS_COLOR_GRAY=8
PS_COLOR_LRED=9
PS_COLOR_LGREEN=10
PS_COLOR_YELLOW=11
PS_COLOR_LBLUE=12
PS_COLOR_LMAGENTA=13
PS_COLOR_LCYAN=14
PS_COLOR_WHITE=15
# Line Graphisc, see terminfo
PS_ACS_HLINE=q
PS_ACS_VLINE=x
PS_ACS_LRCORNER=j
PS_ACS_URCORNER=k
PS_ACS_ULCORNER=l
PS_ACS_LLCORNER=m
# Default colors (maybe later if[] for white background)
DEF_PS_COLOR_DEF=$PS_COLOR_WHITE
DEF_PS_COLOR_USER=$PS_COLOR_LGREEN
DEF_PS_COLOR_ROOT=$PS_COLOR_LRED
DEF_PS_COLOR_DIR=$PS_COLOR_LCYAN
# Supported command setf/setaf?
SETF=setf
tput $SETF 0 || SETF=setaf
PS_COLOR_DEF=
PS_COLOR_USER=
PS_COLOR_ROOT=
PS_COLOR_DIR=
# colors?
if [[ "${color_prompt}" == yes ]]; then
PS_COLOR_DEF=$(tput_to_str $SETF $PS_COLOR_WHITE)
PS_COLOR_USER=$(tput_to_str $SETF $PS_COLOR_LGREEN)
PS_COLOR_ROOT=$(tput_to_str $SETF $PS_COLOR_LRED)
PS_COLOR_DIR=$(tput_to_str $SETF $PS_COLOR_LCYAN)
fi
# RED color for root
if [[ "${UID}" == "0" ]]; then
PS_COLOR_USER=${PS_COLOR_ROOT}
fi
# turn off all atributes
PS_ALL_ATTR_OFF=$(tput_to_str sgr0)
# Alternate character set
PS_ACS_ON=$(tput_to_str smacs)
PS_ACS_OFF=$(tput_to_str rmacs)
PS_LINE1=""
PS_LINE2=""
PS_LINE1=${SSH_TTY:+"\[${PS_ACS_ON}\]${PS_ACS_ULCORNER}${PS_ACS_HLINE}\[${PS_ACS_OFF}\]"}
PS_LINE2=${SSH_TTY:+"\n\[${PS_ACS_ON}\]${PS_ACS_LLCORNER}${PS_ACS_HLINE}${PS_ACS_HLINE}\[${PS_ACS_OFF}\]{"}
PS_LINE1+="{\[${PS_COLOR_USER}\]\u@\h\[${PS_COLOR_DEF}\]}"
PS_LINE1+="{\[${PS_COLOR_DIR}\]\w\[${PS_COLOR_DEF}\]}"
PS_LINE2+="\[${PS_ALL_ATTR_OFF}\]\\$"
#echo "${PS_LINE1}\$(prompt_command)${PS_LINE2} "
echo "${PS_LINE1}\${PS_EXCODE}${PS_LINE2} "
}
function prompt_command() {
EC=$?
PS_EXCODE=""
if [ $EC -ne 0 ]; then PS_EXCODE="[$EC]"; fi
}
PROMPT_COMMAND=prompt_command
PS1=$(prompt)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment