bash/bashrc

217 lines
6.7 KiB
Bash
Raw Normal View History

2023-09-17 17:52:09 +00:00
_WHITE='\033[1;37m' # White
_NC='\033[0m' # No Color
2022-03-12 17:13:43 +00:00
export SHELL_CONFIG="$SHELL_CONFIG:.bashrc"
#
# ~/.bashrc
#
2023-09-17 17:52:09 +00:00
function show_date() {
2023-09-17 18:01:58 +00:00
# Define the dot file to store the selected adjective
dotfile="$HOME/.adjective_of_the_day"
2023-09-17 18:09:47 +00:00
# Check if the dot file exists and was modified since yesterday
2023-09-17 18:01:58 +00:00
if [[ -f "$dotfile" && $(date -d "$(stat -c %y "$dotfile")" +%s) -ge $(date -d 'yesterday' +%s) ]]; then
2023-09-17 18:09:47 +00:00
# If the dot file exists and was modified since yesterday
2023-09-17 18:01:58 +00:00
# read the stored adjective from the file
selected_adjective=$(cat "$dotfile")
else
# Define an array of adjectives with classifications
adjectives=(
"beautiful:positive"
"engaging:positive"
"majestic:positive"
"distinguished:positive"
"venerable:positive"
"formal:positive"
"elegant:positive"
"serene:positive"
"graceful:positive"
"regal:positive"
"noble:positive"
"miserable:negative"
"worthless:negative"
"depressing:negative"
"soulless:negative"
"desolate:negative"
"archaic:negative"
"grim:negative"
"dreadful:negative"
"forlorn:negative"
"wretched:negative"
"neutral:neutral"
"ordinary:neutral"
"common:neutral"
"antique:neutral"
"ceremonial:neutral"
"timeless:neutral"
"classic:neutral"
"historic:neutral"
"ancient:neutral"
)
# Select a random adjective from the array
selected_adjective="${adjectives[$RANDOM % ${#adjectives[@]}]}"
# Store the selected adjective in the dot file
echo "$selected_adjective" > "$dotfile"
fi
# Split the selected adjective into the adjective and classification parts
IFS=':' read -r adjective classification <<< "$selected_adjective"
# Determine the color code based on the classification
case "$classification" in
"positive") text_color="\033[1;32m";;
"negative") text_color="\033[1;31m";;
*) text_color="";; # Default to no colour
esac
# ANSI escape codes for reset
reset_color='\033[0m'
hl_color='\033[1;34m'
# Get the current day of the week, day of the month, and year
day_of_week=$(date "+%A")
day_of_month=$(date "+%d")
month_name=$(date "+%B")
year=$(date "+%Y")
# Determine the day suffix (th, nd, rd)
case "$day_of_month" in
1[0-9]) day_suffix="th";;
*1) day_suffix="st";;
*2) day_suffix="nd";;
*3) day_suffix="rd";;
*) day_suffix="th";;
esac
# Create the full date format with colored parts and the selected adjective
full_date="Pray, be informed, on this ${text_color}${adjective}${reset_color} day,\n${hl_color}${day_of_week}${reset_color} the ${hl_color}${day_of_month}${day_suffix}${reset_color} day of ${hl_color}${month_name}${reset_color}, in the year of our Lord ${hl_color}${year}${reset_color}!"
# Print the full date
echo -e "$full_date"
echo ""
2023-09-17 17:52:09 +00:00
}
2023-09-17 18:01:58 +00:00
2022-03-12 17:13:43 +00:00
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
export HISTCONTROL=ignoreboth:erasedups
2022-03-12 17:36:58 +00:00
[ -f "$HOME/.config/bash/gitstatus/gitstatus.prompt.sh" ] && . "$HOME/.config/bash/gitstatus/gitstatus.prompt.sh"
PS1='\t \[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\]${GITSTATUS_PROMPT:+ $GITSTATUS_PROMPT}\n\[\033[01;$((31+!$?))m\]\$\[\033[00m\] \[\e]0;\u@\h: \w\a\]'
2022-03-12 17:13:43 +00:00
2022-03-12 17:58:46 +00:00
# If there are multiple matches for completion, Tab should cycle through them
bind TAB:menu-complete
# Display a list of the matching files
bind "set show-all-if-ambiguous on"
# Perform partial (common) completion on the first Tab press, only start
# cycling full results on the second Tab press (from bash version 5)
bind "set menu-complete-display-prefix on"
2023-09-17 17:52:09 +00:00
show_date;
2022-03-12 17:13:43 +00:00
source ~/.profile
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
2022-03-13 18:49:36 +00:00
# https://github.com/skywind3000/z.lua
2022-11-23 14:40:59 +00:00
if command -v lua ; then
2022-03-13 18:49:36 +00:00
eval "$(lua $HOME/.z.lua/z.lua --init bash enhanced once echo)"
2022-11-23 14:40:59 +00:00
fi > /dev/null
2022-03-22 13:00:31 +00:00
_mem_available=$(awk '/MemAvailable/ { printf "%.1f \n", $2/1024/1024 }' /proc/meminfo)
2022-03-22 15:43:36 +00:00
_updates_available="$(wc -l $HOME/.checkupdates | cut -d' ' -f1)"
2022-03-22 13:00:31 +00:00
[ -z $_updates_available ] && _updates_available="0"
2022-03-22 15:43:36 +00:00
echo "Remember your commands:"
2023-09-17 17:52:09 +00:00
echo -e " ${_WHITE}cheat vimv 'flameshot gui' mid3v2 zathura tesseract remmina${_NC}"
2022-03-22 15:44:06 +00:00
echo ""
2022-03-22 15:43:36 +00:00
2022-03-22 13:00:31 +00:00
if [ ${_mem_available%.*} -lt 5 ] ; then
2022-11-23 14:40:59 +00:00
echo -ne "Memory available: \033[0;33m"
2022-03-22 13:00:31 +00:00
[ ${_mem_available%.*} -lt 3 ] && echo -ne "\033[0;31m"
echo -n "${_mem_available}"
2022-11-23 14:40:59 +00:00
echo -e "GB\033[0m"
2022-03-22 13:00:31 +00:00
fi
if [ $_updates_available -gt 0 ] ; then
2023-09-17 17:52:09 +00:00
echo -ne "Updates available: \033[1;37m"
2022-11-23 14:40:59 +00:00
[ $_updates_available -gt 15 ] && echo -ne "\033[0;33m"
2022-06-15 14:59:01 +00:00
[ $_updates_available -gt 29 ] && echo -ne "\033[0;31m"
2022-11-23 14:40:59 +00:00
echo -ne "$_updates_available\033[0m"
2023-10-10 10:51:49 +00:00
echo -ne " [ update with: \033[1;31mupdate\033[0m ]"
2022-03-22 13:00:31 +00:00
echo ""
fi
2023-09-17 17:52:09 +00:00
echo ""
echo -e "Remember \"\033[1;34mTODO.md\033[0m\" files have content automatically displayed."
2022-03-22 13:00:31 +00:00
echo ""
2022-05-22 10:40:07 +00:00
. "$HOME/.config/bash/cheat.bash"
2022-11-23 14:40:59 +00:00
if command -v checkupdates ; then
(checkupdates > "$HOME/.checkupdates") & disown
fi > /dev/null
2022-08-19 13:35:40 +00:00
. "$HOME/.cargo/env"
2022-11-23 14:40:59 +00:00
alias backup='sudo borgmatic create --verbosity 1 --files'
2023-08-22 09:38:47 +00:00
# Function to check for TODO.md and echo its contents
function check_todo() {
if [ -f "TODO.md" ]; then
echo
echo -e "\e[91mTODO.md\e[0m"
echo "---------------------------"
mdcat TODO.md
echo "---------------------------"
echo
fi
}
# Hook to execute check_todo when changing directories
cd() {
builtin cd "$@"
check_todo
}
2023-08-22 10:25:20 +00:00
random-bg() {
local color='xxx'
while getopts ":mrgb" opt; do
case $opt in
m) muted=true ;;
r) color="ffxx" ;;
g) color="xffx" ;;
b) color="xxff" ;;
*) echo "Invalid option: -$OPTARG" >&2
return 1 ;;
esac
done
if [ "$muted" = true ]; then
# FIXME sometimes gives 7 digit value
# note value of 30 works
hue_range=360 # Restricted hue range (0-360 degrees)
hue=$((RANDOM % $hue_range))
saturation_range="50-80" # Adjust as needed
saturation=$((RANDOM % ($saturation_range + 1) + ${saturation_range%-*}))
lightness_range="60-80" # Adjust as needed
lightness=$((RANDOM % ($lightness_range + 1) + ${lightness_range%-*}))
color=$(printf "%02x%02x%02x" "$hue" "$saturation" "$lightness")
else
# FIXME: each x is replaced with same value, need a different value for each x
color=${color//x/$(openssl rand -hex 1)}
fi
echo "#$color"
xsetroot -solid "#$color"
}