Skip to content

Instantly share code, notes, and snippets.

@vinit-chauhan
Last active February 10, 2024 17:33
QoL bash configs. :)
#!/bin/bash
# To use this, clone this file and add following line at the end of your .bashrc
# `eval "$(cat PATH_TO_THIS_FILE)"`
# Function to get and display IP address if it exists
get_ip() {
local interface="$1"
local ip_address=$(ip addr show "$interface" | awk '/inet /{print $2}' | cut -d'/' -f1)
if [ -n "$ip_address" ]; then
echo $ip_address
else
echo Unknown
fi
}
# Gets width of the console
console_width=$(tput cols)
# prints a line with desired separator
print_separator() {
local char="${1:- }"
local line=""
for ((i = 0; i < $console_width; i++)); do
line+=$char
done
echo $line
}
# Print a line with message text, and add appropriate padding
print_line() {
local message="$1"
local line="## $message"
local line_length=$(expr length "$line")
local space_count=$((console_width - 4 - line_length))
if [ $line_length -lt $console_width ]; then
temp=""
for ((i = 0 ; i < $space_count ; i++ )); do
temp="$temp "
done
line="$line$temp ##"
echo "$line"
else
line+="##"
fi
}
# Welcome Message
print_separator "#"
print_line "Hello, $(whoami)"
print_line
print_line "Local IP Address"
print_line "-- Ethernet: $(get_ip "enp3s0")"
print_line "-- Wireless: $(get_ip "wlo1")"
print_line "Public IP : $(wget -O - -q https://checkip.amazonaws.com)"
print_line
print_line "Login time: $(date)"
print_separator "#"
# Remove useless commands. :)
alias clear='echo "Dont use Clear, use Ctrl+l instead"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment