2021-02-06 00:31:49 +01:00
|
|
|
#!/bin/bash
|
2022-03-09 23:11:26 +01:00
|
|
|
|
2022-10-27 16:49:31 +02:00
|
|
|
######################################################################
|
|
|
|
# 🌞 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> #
|
|
|
|
######################################################################
|
2021-02-05 23:18:13 +01:00
|
|
|
|
2022-10-27 16:49:31 +02:00
|
|
|
# Formatting variables
|
|
|
|
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 () {
|
2022-08-06 21:25:55 +02:00
|
|
|
h=`date +%H`
|
2022-10-27 16:49:31 +02:00
|
|
|
if [ $h -lt 04 ] || [[ $h -gt 22 ]];
|
|
|
|
then greeting="Good Night"
|
|
|
|
elif [ $h -lt 12 ];
|
|
|
|
then greeting="Good morning"
|
|
|
|
elif [ $h -lt 18 ];
|
|
|
|
then greeting="Good afternoon"
|
|
|
|
elif [ $h -lt 22 ];
|
|
|
|
then greeting="Good evening"
|
|
|
|
else
|
|
|
|
greeting="Hello"
|
2022-08-06 21:25:55 +02:00
|
|
|
fi
|
2022-08-12 13:22:45 +02:00
|
|
|
WELCOME_MSG="$greeting $USER!"
|
2022-08-06 21:25:55 +02:00
|
|
|
if hash lolcat 2>/dev/null && hash figlet 2>/dev/null; then
|
|
|
|
echo "${WELCOME_MSG}" | figlet | lolcat
|
|
|
|
else
|
2022-10-27 16:49:31 +02:00
|
|
|
echo -e "$COLOR_P${WELCOME_MSG}${RESET}\n"
|
2022-08-06 21:25:55 +02:00
|
|
|
fi
|
2022-10-27 16:49:31 +02:00
|
|
|
}
|
2021-02-05 23:18:13 +01:00
|
|
|
|
2022-10-27 16:49:31 +02:00
|
|
|
# Print system information with neofetch, if it's installed
|
|
|
|
function welcome_sysinfo () {
|
2022-08-06 21:25:55 +02:00
|
|
|
if hash neofetch 2>/dev/null; then
|
|
|
|
neofetch --shell_version off \
|
2023-11-11 21:38:30 +01:00
|
|
|
--disable kernel distro shell resolution de wm wm_theme theme icons term packages \
|
2022-08-06 21:25:55 +02:00
|
|
|
--backend off \
|
|
|
|
--colors 4 8 4 4 8 6 \
|
|
|
|
--color_blocks off \
|
|
|
|
--memory_display info
|
|
|
|
fi
|
2022-10-27 16:49:31 +02:00
|
|
|
}
|
2022-08-06 21:25:55 +02:00
|
|
|
|
2022-10-27 16:49:31 +02:00
|
|
|
# Print todays info: Date, IP, weather, etc
|
|
|
|
function welcome_today () {
|
2023-11-11 21:38:30 +01:00
|
|
|
timeout=0.5
|
2022-10-27 16:49:31 +02:00
|
|
|
echo -e "\033[1;34mToday\n------"
|
2022-03-09 23:11:26 +01:00
|
|
|
|
2022-08-06 21:25:55 +02:00
|
|
|
# Print date time
|
2022-10-27 16:49:31 +02:00
|
|
|
echo -e "$COLOR_S$(date '+🗓️ Date: %A, %B %d, %Y at %H:%M')"
|
2022-03-09 23:11:26 +01:00
|
|
|
|
2022-08-06 21:25:55 +02:00
|
|
|
# Print local weather
|
2023-02-26 13:59:50 +01:00
|
|
|
curl -s -m $timeout "https://wttr.in?format=%cWeather:+%C+%t,+%p+%w"
|
2022-10-27 16:49:31 +02:00
|
|
|
echo -e "${RESET}"
|
2022-03-09 23:11:26 +01:00
|
|
|
|
2022-08-06 21:25:55 +02:00
|
|
|
# Print IP address
|
2022-08-12 13:22:45 +02:00
|
|
|
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_interface=$(ip route get 8.8.8.8 | awk -F"dev " 'NR==1{split($2,a," ");print a[1]}')
|
2022-10-27 16:49:31 +02:00
|
|
|
echo -e "${COLOR_S}🌐 IP: $(curl -s -m $timeout 'https://ipinfo.io/ip') (${ip_address} on ${ip_interface})"
|
|
|
|
echo -e "${RESET}\n"
|
2022-08-12 13:22:45 +02:00
|
|
|
fi
|
2022-08-06 21:25:55 +02:00
|
|
|
}
|
|
|
|
|
2022-10-27 16:49:31 +02:00
|
|
|
# Putting it all together
|
|
|
|
function welcome() {
|
|
|
|
welcome_greeting
|
|
|
|
welcome_sysinfo
|
|
|
|
welcome_today
|
|
|
|
}
|
|
|
|
|
2022-08-06 21:25:55 +02:00
|
|
|
# Determine if file is being run directly or sourced
|
|
|
|
([[ -n $ZSH_EVAL_CONTEXT && $ZSH_EVAL_CONTEXT =~ :file$ ]] ||
|
|
|
|
[[ -n $KSH_VERSION && $(cd "$(dirname -- "$0")" &&
|
|
|
|
printf '%s' "${PWD%/}/")$(basename -- "$0") != "${.sh.file}" ]] ||
|
|
|
|
[[ -n $BASH_VERSION ]] && (return 0 2>/dev/null)) && sourced=1 || sourced=0
|
|
|
|
|
2023-03-16 18:26:44 +01:00
|
|
|
# If script being called directly run immediately
|
2022-08-06 21:25:55 +02:00
|
|
|
if [ $sourced -eq 0 ]; then
|
|
|
|
welcome $@
|
|
|
|
fi
|
2022-03-09 23:11:26 +01:00
|
|
|
|
2021-02-05 23:18:13 +01:00
|
|
|
# EOF
|