Clean binaryanomaly

pull/1790/head
BarbUk 2021-01-16 09:12:20 +01:00
parent fb0fa7f799
commit cfb9a22e70
No known key found for this signature in database
GPG Key ID: DB301C759539E9FE
1 changed files with 43 additions and 45 deletions

View File

@ -1,80 +1,78 @@
#!/usr/bin/env bash # shellcheck shell=bash
# Detect whether a reboot is required # Detect whether a reboot is required
function show_reboot_required() { function show_reboot_required() {
if [ ! -z "$_bf_prompt_reboot_info" ]; then if [ -n "$_bf_prompt_reboot_info" ]; then
if [ -f /var/run/reboot-required ]; then if [ -f /var/run/reboot-required ]; then
printf "Reboot required!" printf "Reboot required!"
fi fi
fi fi
} }
# Set different host color for local and remote sessions # Set different host color for local and remote sessions
function set_host_color() { function set_host_color() {
# Detect if connection is through SSH # Detect if connection is through SSH
if [[ ! -z $SSH_CLIENT ]]; then if [[ -n $SSH_CLIENT ]]; then
printf "${lime_yellow}" printf '%s' "${lime_yellow}"
else else
printf "${light_orange}" printf '%s' "${light_orange}"
fi fi
} }
# Set different username color for users and root # Set different username color for users and root
function set_user_color() { function set_user_color() {
case $(id -u) in case $(id -u) in
0) 0)
printf "${red}" printf '%s' "${red}"
;; ;;
*) *)
printf "${cyan}" printf '%s' "${cyan}"
;; ;;
esac esac
} }
scm_prompt() { scm_prompt() {
CHAR=$(scm_char) CHAR=$(scm_char)
if [ $CHAR = $SCM_NONE_CHAR ] if [ "$CHAR" = "$SCM_NONE_CHAR" ]; then
then return
return else
else echo "[$(scm_char)$(scm_prompt_info)]"
echo "[$(scm_char)$(scm_prompt_info)]" fi
fi
} }
# Define custom colors we need # Define custom colors we need
# non-printable bytes in PS1 need to be contained within \[ \]. # non-printable bytes in PS1 need to be contained within \[ \].
# Otherwise, bash will count them in the length of the prompt # Otherwise, bash will count them in the length of the prompt
function set_custom_colors() { function set_custom_colors() {
dark_grey="\[$(tput setaf 8)\]" dark_grey="\[$(tput setaf 8)\]"
light_grey="\[$(tput setaf 248)\]" light_grey="\[$(tput setaf 248)\]"
light_orange="\[$(tput setaf 172)\]" light_orange="\[$(tput setaf 172)\]"
bright_yellow="\[$(tput setaf 220)\]" bright_yellow="\[$(tput setaf 220)\]"
lime_yellow="\[$(tput setaf 190)\]" lime_yellow="\[$(tput setaf 190)\]"
powder_blue="\[$(tput setaf 153)\]" powder_blue="\[$(tput setaf 153)\]"
} }
__ps_time() { __ps_time() {
echo "$(clock_prompt)${normal}\n" printf '%s' "$(clock_prompt)${normal}\n"
} }
function prompt_command() { function prompt_command() {
ps_reboot="${bright_yellow}$(show_reboot_required)${normal}\n" ps_reboot="${bright_yellow}$(show_reboot_required)${normal}\n"
ps_username="$(set_user_color)\u${normal}" ps_username="$(set_user_color)\u${normal}"
ps_uh_separator="${dark_grey}@${normal}" ps_uh_separator="${dark_grey}@${normal}"
ps_hostname="$(set_host_color)\h${normal}" ps_hostname="$(set_host_color)\h${normal}"
ps_path="${yellow}\w${normal}" ps_path="${yellow}\w${normal}"
ps_scm_prompt="${light_grey}$(scm_prompt)" ps_scm_prompt="${light_grey}$(scm_prompt)"
ps_user_mark="${normal} ${normal}" ps_user_mark="${normal} ${normal}"
ps_user_input="${normal}" ps_user_input="${normal}"
# Set prompt # Set prompt
PS1="$ps_reboot$(__ps_time)$ps_username$ps_uh_separator$ps_hostname $ps_path $ps_scm_prompt$ps_user_mark$ps_user_input" PS1="$ps_reboot$(__ps_time)$ps_username$ps_uh_separator$ps_hostname $ps_path $ps_scm_prompt$ps_user_mark$ps_user_input"
} }
# Initialize custom colors # Initialize custom colors