mirror of
https://github.com/Lissy93/dotfiles.git
synced 2024-11-29 02:33:21 +01:00
Split big welcome function into individual methods
This commit is contained in:
parent
75f331ceb5
commit
b5519382c7
66
utils/welcome-banner.sh
Normal file → Executable file
66
utils/welcome-banner.sh
Normal file → Executable file
@ -1,32 +1,44 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Welcome script, prints personalised, time-based greeting and system info
|
######################################################################
|
||||||
# Licensed under MIT, (C) Alicia Sykes 2021: https://aliciasykes.com
|
# 🌞 Welcome Banner #
|
||||||
|
######################################################################
|
||||||
|
# Prints personal greeting, system info and data about today #
|
||||||
|
# Intended for use as a MOTD, for when using multiple systems #
|
||||||
|
# For docs and more info, see: https://github.com/lissy93/dotfiles #
|
||||||
|
# #
|
||||||
|
# Licensed under MIT (C) Alicia Sykes 2022 <https://aliciasykes.com> #
|
||||||
|
######################################################################
|
||||||
|
|
||||||
function welcome() {
|
# Formatting variables
|
||||||
# Determine greeting based on the time of day
|
COLOR_P='\033[1;36m'
|
||||||
|
COLOR_S='\033[0;36m'
|
||||||
|
RESET='\033[0m'
|
||||||
|
|
||||||
|
# Print time-based personalized message, using figlet & lolcat if availible
|
||||||
|
function welcome_greeting () {
|
||||||
h=`date +%H`
|
h=`date +%H`
|
||||||
if [ $h -lt 04 ] || [[ $h -gt 22 ]]; then greeting="Good Night"
|
if [ $h -lt 04 ] || [[ $h -gt 22 ]];
|
||||||
elif [ $h -lt 12 ]; then greeting="Good morning"
|
then greeting="Good Night"
|
||||||
elif [ $h -lt 18 ]; then greeting="Good afternoon"
|
elif [ $h -lt 12 ];
|
||||||
elif [ $h -lt 22 ]; then greeting="Good evening"
|
then greeting="Good morning"
|
||||||
else greeting="Hello"
|
elif [ $h -lt 18 ];
|
||||||
|
then greeting="Good afternoon"
|
||||||
|
elif [ $h -lt 22 ];
|
||||||
|
then greeting="Good evening"
|
||||||
|
else
|
||||||
|
greeting="Hello"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
COLOR_P="\033[1;36m"
|
|
||||||
COLOR_S="\033[0;36m"
|
|
||||||
|
|
||||||
# Make welcome message
|
|
||||||
WELCOME_MSG="$greeting $USER!"
|
WELCOME_MSG="$greeting $USER!"
|
||||||
|
|
||||||
# Print welcome message, using figlet & lolcat if availible
|
|
||||||
if hash lolcat 2>/dev/null && hash figlet 2>/dev/null; then
|
if hash lolcat 2>/dev/null && hash figlet 2>/dev/null; then
|
||||||
echo "${WELCOME_MSG}" | figlet | lolcat
|
echo "${WELCOME_MSG}" | figlet | lolcat
|
||||||
else
|
else
|
||||||
echo -e "$COLOR_P${WELCOME_MSG}\033[0m\n"
|
echo -e "$COLOR_P${WELCOME_MSG}${RESET}\n"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Print system information with neofetch, if it's installed
|
# Print system information with neofetch, if it's installed
|
||||||
|
function welcome_sysinfo () {
|
||||||
if hash neofetch 2>/dev/null; then
|
if hash neofetch 2>/dev/null; then
|
||||||
neofetch --shell_version off \
|
neofetch --shell_version off \
|
||||||
--disable shell resolution de wm wm_theme theme icons terminal \
|
--disable shell resolution de wm wm_theme theme icons terminal \
|
||||||
@ -35,26 +47,36 @@ function welcome() {
|
|||||||
--color_blocks off \
|
--color_blocks off \
|
||||||
--memory_display info
|
--memory_display info
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Print todays info: Date, IP, weather, etc
|
||||||
|
function welcome_today () {
|
||||||
timeout=0.5
|
timeout=0.5
|
||||||
|
echo -e "\033[1;34mToday\n------"
|
||||||
echo "\033[1;34mToday\n------"
|
|
||||||
|
|
||||||
# Print date time
|
# Print date time
|
||||||
echo "$COLOR_S$(date '+🗓️ Date: %A, %B %d, %Y at %H:%M')"
|
echo -e "$COLOR_S$(date '+🗓️ Date: %A, %B %d, %Y at %H:%M')"
|
||||||
|
|
||||||
# Print local weather
|
# Print local weather
|
||||||
curl -s -m $timeout "wttr.in?format=%cWeather:+%C+%t,+%p+%w"
|
curl -s -m $timeout "wttr.in?format=%cWeather:+%C+%t,+%p+%w"
|
||||||
echo -e "\033[0m"
|
echo -e "${RESET}"
|
||||||
|
|
||||||
# Print IP address
|
# Print IP address
|
||||||
if hash ip 2>/dev/null; then
|
if hash ip 2>/dev/null; then
|
||||||
ip_address=$(ip route get 8.8.8.8 | awk -F"src " 'NR==1{split($2,a," ");print a[1]}')
|
ip_address=$(ip route get 8.8.8.8 | awk -F"src " 'NR==1{split($2,a," ");print a[1]}')
|
||||||
ip_interface=$(ip route get 8.8.8.8 | awk -F"dev " 'NR==1{split($2,a," ");print a[1]}')
|
ip_interface=$(ip route get 8.8.8.8 | awk -F"dev " 'NR==1{split($2,a," ");print a[1]}')
|
||||||
echo "${COLOR_S}🌐 IP: $(curl -s -m $timeout 'https://ipinfo.io/ip') (${ip_address} on ${ip_interface})\033[0m\n"
|
echo -e "${COLOR_S}🌐 IP: $(curl -s -m $timeout 'https://ipinfo.io/ip') (${ip_address} on ${ip_interface})"
|
||||||
|
echo -e "${RESET}\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Putting it all together
|
||||||
|
function welcome() {
|
||||||
|
welcome_greeting
|
||||||
|
welcome_sysinfo
|
||||||
|
welcome_today
|
||||||
|
}
|
||||||
|
|
||||||
# Determine if file is being run directly or sourced
|
# Determine if file is being run directly or sourced
|
||||||
([[ -n $ZSH_EVAL_CONTEXT && $ZSH_EVAL_CONTEXT =~ :file$ ]] ||
|
([[ -n $ZSH_EVAL_CONTEXT && $ZSH_EVAL_CONTEXT =~ :file$ ]] ||
|
||||||
[[ -n $KSH_VERSION && $(cd "$(dirname -- "$0")" &&
|
[[ -n $KSH_VERSION && $(cd "$(dirname -- "$0")" &&
|
||||||
|
Loading…
Reference in New Issue
Block a user