Add ssh indicator to prompt
Signed-off-by: Aleksandar 'The Cobra' Widulski <thecobra@riseup.net>
This commit is contained in:
parent
89e0dd41a7
commit
7f2dcac198
49
.prompt
49
.prompt
|
@ -33,12 +33,10 @@ __get_cmd_time() {
|
||||||
|
|
||||||
__sig() {
|
__sig() {
|
||||||
# Giant switch case for getting the name of the signal (`kill -l`)
|
# Giant switch case for getting the name of the signal (`kill -l`)
|
||||||
local RED="\[\033[31m\]"
|
|
||||||
local WHT="\[\033[37m\]"
|
|
||||||
j=0
|
j=0
|
||||||
for i in $@; do
|
for i in $@; do
|
||||||
if [[ $j != 0 ]]; then
|
if [[ $j != 0 ]]; then
|
||||||
printf '%s|%s' "$WHT" "$RED"
|
printf '%s|%s' "$_WHT" "$_RED"
|
||||||
fi
|
fi
|
||||||
j=$((j+1))
|
j=$((j+1))
|
||||||
case $i in
|
case $i in
|
||||||
|
@ -81,6 +79,18 @@ __sig() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__ssh() {
|
||||||
|
local CON=($SSH_CONNECTION)
|
||||||
|
local SRV_IP="${CON[2]}"
|
||||||
|
[[ -z "$SRV_IP" ]] && return
|
||||||
|
local SRV_PORT="${CON[3]}"
|
||||||
|
# 4 chars from startand 4 chars from end
|
||||||
|
local SRV_IP_CUT="${_CYN}${SRV_IP}"
|
||||||
|
[[ ${#SRV_IP} -gt 8 ]] && local SRV_IP_CUT="${_CYN}${SRV_IP:0:4}${_WHT}*${_CYN}${SRV_IP: -4}"
|
||||||
|
local RET="${_GRN}${_BLU}[${SRV_IP_CUT}${_PRP}${_BLD}:${_NON}${_CYN}${SRV_PORT}${_BLU}]${_NON}"
|
||||||
|
printf '%s' "$RET"
|
||||||
|
}
|
||||||
|
|
||||||
__prompt() {
|
__prompt() {
|
||||||
# Get exit code
|
# Get exit code
|
||||||
local PLC=(${PIPESTATUS[@]})
|
local PLC=(${PIPESTATUS[@]})
|
||||||
|
@ -112,40 +122,43 @@ __prompt() {
|
||||||
# Set prompt sections
|
# Set prompt sections
|
||||||
|
|
||||||
# Colors
|
# Colors
|
||||||
local NON="\[\033[0m\]"
|
_NON="\[\033[0m\]"
|
||||||
local BLD="\[\033[1m\]" # YEP BALD
|
_BLD="\[\033[1m\]" # YEP BALD
|
||||||
local BLK="\[\033[30m\]"
|
_BLK="\[\033[30m\]"
|
||||||
local RED="\[\033[31m\]"
|
_RED="\[\033[31m\]"
|
||||||
local GRN="\[\033[32m\]"
|
_GRN="\[\033[32m\]"
|
||||||
local YLW="\[\033[33m\]"
|
_YLW="\[\033[33m\]"
|
||||||
local BLU="\[\033[34m\]"
|
_BLU="\[\033[34m\]"
|
||||||
local PRP="\[\033[35m\]"
|
_PRP="\[\033[35m\]"
|
||||||
local CYN="\[\033[36m\]"
|
_CYN="\[\033[36m\]"
|
||||||
local WHT="\[\033[37m\]"
|
_WHT="\[\033[37m\]"
|
||||||
|
|
||||||
# Text
|
# Text
|
||||||
|
|
||||||
|
# ssh detection and indicator
|
||||||
|
[[ "$SSH_CONNECTION" ]] && local SSH="$(__ssh) "
|
||||||
|
|
||||||
# [INT], [4], etc.
|
# [INT], [4], etc.
|
||||||
for i in ${PLC[@]}; do
|
for i in ${PLC[@]}; do
|
||||||
if [[ $i > 0 ]]; then
|
if [[ $i > 0 ]]; then
|
||||||
local SIG="$(printf '%s[%s%s%s] ' "$BLU" "$RED" "$(__sig ${PLC[@]})" "$BLU")"
|
local SIG="$(printf '%s[%s%s%s] ' "$_BLU" "$_RED" "$(__sig ${PLC[@]})" "$_BLU")"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# [user@homeserver:~]
|
# [user@homeserver:~]
|
||||||
local COL="$([[ $UID == 0 ]] && printf '%s' "$RED" || printf '%s' "$YLW")"
|
local COL="$([[ $UID == 0 ]] && printf '%s' "$_RED" || printf '%s' "$_YLW")"
|
||||||
local UHD="${BLD}${BLU}[${COL}\u${PRP}@${CYN}\h${PRP}:${GRN}\w${BLU}]"
|
local UHD="${_BLD}${_BLU}[${COL}\u${_PRP}@${_CYN}\h${_PRP}:${_GRN}\w${_BLU}]"
|
||||||
|
|
||||||
# 2y 351d 12m 43s 382969μs
|
# 2y 351d 12m 43s 382969μs
|
||||||
local TIME="${YLW}$(__get_cmd_time)"
|
local TIME="${_YLW}$(__get_cmd_time)"
|
||||||
|
|
||||||
# Random colored $ or #
|
# Random colored $ or #
|
||||||
local RAND256="\[\033[38;2;$RANDOM;$RANDOM;${RANDOM}m\]"
|
local RAND256="\[\033[38;2;$RANDOM;$RANDOM;${RANDOM}m\]"
|
||||||
local IND="${RAND256}\\$"
|
local IND="${RAND256}\\$"
|
||||||
|
|
||||||
# Set the prompt
|
# Set the prompt
|
||||||
PS1="${NON}${SIG}${UHD} ${TIME} ${IND} ${NON}"
|
PS1="${_NON}${SSH}${SIG}${UHD} ${TIME} ${IND} ${_NON}"
|
||||||
}
|
}
|
||||||
|
|
||||||
PROMPT_COMMAND=__prompt
|
PROMPT_COMMAND=__prompt
|
||||||
|
|
Loading…
Reference in New Issue