update
This commit is contained in:
parent
7f80789209
commit
35a624eedb
3 changed files with 124 additions and 107 deletions
|
|
@ -1,8 +1,6 @@
|
|||
#
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# ~/.bash_profile
|
||||
#
|
||||
|
||||
[[ -r ~/.profile ]] && . ~/.profile
|
||||
[[ -f ~/.bashrc ]] && . ~/.bashrc
|
||||
|
||||
source /home/ray/.config/broot/launcher/bash/br
|
||||
. "$HOME/.cargo/env"
|
||||
|
|
|
|||
219
bashrc
219
bashrc
|
|
@ -1,19 +1,11 @@
|
|||
# shellcheck shell=bash
|
||||
|
||||
# If not running interactively, don't do anything.
|
||||
[[ $- != *i* ]] && return
|
||||
|
||||
# Color definitions
|
||||
_WHITE='\033[1;37m' # White
|
||||
_NC='\033[0m' # 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
|
||||
_NC='\033[0m' # No color
|
||||
|
||||
_RED='\033[0;31m' # Red
|
||||
_GREEN='\033[01;32m' # Bright Green
|
||||
|
|
@ -24,12 +16,16 @@ _BRIGHT_RED='\033[1;31m' # Bright Red (for negative)
|
|||
_BRIGHT_WHITE='\033[1;37m' # Bright White
|
||||
_DIM_RED='\033[91m' # Bright Red (for TODO files)
|
||||
|
||||
export SHELL_CONFIG="$SHELL_CONFIG:.bashrc"
|
||||
export SHELL_CONFIG="${SHELL_CONFIG:+${SHELL_CONFIG}:}.bashrc"
|
||||
#
|
||||
# ~/.bashrc
|
||||
#
|
||||
|
||||
function show_date() {
|
||||
local dotfile selected_adjective adjective classification
|
||||
local day_of_week day_of_month month_name year day_suffix text_color full_date
|
||||
local -a adjectives
|
||||
|
||||
# Define the dot file to store the selected adjective
|
||||
dotfile="$HOME/.adjective_of_the_day"
|
||||
|
||||
|
|
@ -116,14 +112,18 @@ function show_date() {
|
|||
}
|
||||
|
||||
|
||||
# If not running interactively, don't do anything
|
||||
[[ $- != *i* ]] && return
|
||||
|
||||
# ============================================================================
|
||||
# SHELL CONFIGURATION
|
||||
# ============================================================================
|
||||
|
||||
export HISTCONTROL=ignoreboth:erasedups
|
||||
export HISTFILE="$HOME/.histfile"
|
||||
export HISTSIZE=10000
|
||||
export HISTFILESIZE=10000
|
||||
shopt -s histappend checkwinsize
|
||||
|
||||
# Disable terminal flow-control keys only when stdin is a terminal.
|
||||
[[ -t 0 ]] && stty -ixon
|
||||
|
||||
# Optimized divider function - simple timestamp without coloring
|
||||
function draw_prompt_divider() {
|
||||
|
|
@ -139,12 +139,6 @@ function draw_prompt_divider() {
|
|||
echo
|
||||
}
|
||||
|
||||
# Function to capture exit code before other PROMPT_COMMAND functions
|
||||
function capture_exit_code() {
|
||||
LAST_COMMAND_EXIT_CODE=$?
|
||||
echo "DEBUG: capture_exit_code sees \$?=$LAST_COMMAND_EXIT_CODE" >&2
|
||||
}
|
||||
|
||||
# Cache static values that don't change during session
|
||||
_CACHED_USER_HOST="$USER@$HOSTNAME"
|
||||
_CACHED_USER_HOST_LENGTH=${#_CACHED_USER_HOST}
|
||||
|
|
@ -167,11 +161,19 @@ function calculate_git_alignment() {
|
|||
printf -v GIT_ALIGNMENT_PADDING '%*s' $needed_padding ''
|
||||
}
|
||||
|
||||
# Persist each command promptly so a crashed terminal loses as little history
|
||||
# as possible. Bash preserves the user's command status while running
|
||||
# PROMPT_COMMAND, so this does not alter the prompt's error indicator or `$?`.
|
||||
function append_new_history() {
|
||||
history -a
|
||||
}
|
||||
|
||||
# Load custom gitstatus configuration
|
||||
[ -f "$HOME/.config/bash/gitstatus-custom.sh" ] && . "$HOME/.config/bash/gitstatus-custom.sh"
|
||||
|
||||
# Set up prompt command to draw divider, update git status and calculate alignment
|
||||
PROMPT_COMMAND="draw_prompt_divider; my_gitstatus_prompt_update; calculate_git_alignment"
|
||||
# Set up prompt command to save history, draw the divider, update git status,
|
||||
# and calculate alignment.
|
||||
PROMPT_COMMAND="append_new_history; draw_prompt_divider; my_gitstatus_prompt_update; calculate_git_alignment"
|
||||
|
||||
# Custom command_not_found_handle function to show errors in red
|
||||
command_not_found_handle() {
|
||||
|
|
@ -190,23 +192,72 @@ bind "set show-all-if-ambiguous on"
|
|||
# cycling full results on the second Tab press (from bash version 5)
|
||||
bind "set menu-complete-display-prefix on"
|
||||
|
||||
show_date;
|
||||
show_date
|
||||
|
||||
source ~/.profile
|
||||
[ -r "$HOME/.config/profile/aliases.sh" ] && . "$HOME/.config/profile/aliases.sh"
|
||||
|
||||
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
|
||||
nvm use default >/dev/null
|
||||
if [[ -s "$NVM_DIR/nvm.sh" ]]; then
|
||||
\. "$NVM_DIR/nvm.sh"
|
||||
nvm use default >/dev/null
|
||||
[[ -s "$NVM_DIR/bash_completion" ]] && \. "$NVM_DIR/bash_completion"
|
||||
fi
|
||||
|
||||
# https://github.com/skywind3000/z.lua
|
||||
if command -v lua ; then
|
||||
eval "$(lua $HOME/.z.lua/z.lua --init bash enhanced once echo)"
|
||||
eval "$(lua "$HOME/.z.lua/z.lua" --init bash enhanced once echo)"
|
||||
fi > /dev/null
|
||||
|
||||
_mem_available=$(awk '/MemAvailable/ { printf "%.1f \n", $2/1024/1024 }' /proc/meminfo)
|
||||
_updates_available="$(wc -l $HOME/.checkupdates | cut -d' ' -f1)"
|
||||
[ -z $_updates_available ] && _updates_available="0"
|
||||
_package_status_cache="${XDG_CACHE_HOME:-$HOME/.cache}/package-status/status"
|
||||
_package_status_attempt="${XDG_CACHE_HOME:-$HOME/.cache}/package-status/last-attempt"
|
||||
_package_status_max_age=3600
|
||||
_package_status_retry_delay=300
|
||||
_package_status_version=""
|
||||
_package_status_checked_at=""
|
||||
_package_status_pacman_log_signature=""
|
||||
_updates_available="0"
|
||||
_orphans_available="0"
|
||||
|
||||
if [ -r "$_package_status_cache" ]; then
|
||||
while IFS='=' read -r _package_status_key _package_status_value; do
|
||||
case "$_package_status_key" in
|
||||
version) _package_status_version="$_package_status_value" ;;
|
||||
updates) _updates_available="$_package_status_value" ;;
|
||||
orphans) _orphans_available="$_package_status_value" ;;
|
||||
checked_at) _package_status_checked_at="$_package_status_value" ;;
|
||||
pacman_log_signature) _package_status_pacman_log_signature="$_package_status_value" ;;
|
||||
esac
|
||||
done < "$_package_status_cache"
|
||||
fi
|
||||
|
||||
_package_status_now=$(date +%s)
|
||||
_package_status_current_pacman_log_signature=$(stat -c '%Y:%s:%i' /var/log/pacman.log 2>/dev/null || echo '0:0:0')
|
||||
|
||||
if ! [[ "$_package_status_version" == "1" \
|
||||
&& "$_updates_available" =~ ^[0-9]+$ \
|
||||
&& "$_orphans_available" =~ ^[0-9]+$ \
|
||||
&& "$_package_status_checked_at" =~ ^[0-9]+$ \
|
||||
&& "$_package_status_pacman_log_signature" =~ ^[0-9]+:[0-9]+:[0-9]+$ \
|
||||
&& $_package_status_now -ge $_package_status_checked_at \
|
||||
&& $((_package_status_now - _package_status_checked_at)) -le $_package_status_max_age \
|
||||
&& "$_package_status_pacman_log_signature" == "$_package_status_current_pacman_log_signature" ]]; then
|
||||
_updates_available="0"
|
||||
_orphans_available="0"
|
||||
|
||||
_package_status_attempt_time=$(stat -c %Y "$_package_status_attempt" 2>/dev/null || echo 0)
|
||||
if ! [[ "$_package_status_attempt_time" =~ ^[0-9]+$ \
|
||||
&& $_package_status_now -ge $_package_status_attempt_time \
|
||||
&& $((_package_status_now - _package_status_attempt_time)) -lt $_package_status_retry_delay ]]; then
|
||||
systemctl --user start --no-block package-status-refresh.service >/dev/null 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
|
||||
unset _package_status_cache _package_status_attempt _package_status_max_age
|
||||
unset _package_status_retry_delay _package_status_attempt_time _package_status_version
|
||||
unset _package_status_checked_at _package_status_pacman_log_signature
|
||||
unset _package_status_now _package_status_current_pacman_log_signature
|
||||
unset _package_status_key _package_status_value
|
||||
|
||||
echo "Remember your commands:"
|
||||
echo -e " ${_WHITE}nap hyprpicker nmcli lftp lxc-wp qv4l2 cheat vimv rclone mid3v2 zathura tesseract remmina${_NC}"
|
||||
|
|
@ -233,7 +284,6 @@ if [ $_updates_available -gt 0 ] ; then
|
|||
echo ""
|
||||
fi
|
||||
|
||||
_orphans_available="$(pacman -Qdtq 2>/dev/null | wc -l)"
|
||||
if [ $_orphans_available -gt 0 ] ; then
|
||||
echo -ne "Orphaned packages: $_BRIGHT_WHITE"
|
||||
|
||||
|
|
@ -255,86 +305,55 @@ echo -e "Remember \"${_BLUE}TODO.md${_NC}\" and \"${_BLUE}autonote.md${_NC}\" fi
|
|||
echo -e "Edit these with ${_BLUE}et${_NC} and ${_BLUE}ea${_NC}"
|
||||
echo ""
|
||||
|
||||
. "$HOME/.config/bash/cheat.bash"
|
||||
|
||||
if command -v checkupdates ; then
|
||||
(checkupdates > "$HOME/.checkupdates") & disown
|
||||
fi > /dev/null
|
||||
|
||||
. "$HOME/.cargo/env"
|
||||
|
||||
alias backup='sudo borgmatic create --verbosity 1 --files'
|
||||
[ -r "$HOME/.config/bash/cheat.bash" ] && . "$HOME/.config/bash/cheat.bash"
|
||||
|
||||
#openai codex completion
|
||||
eval "$(codex completion bash)"
|
||||
if command -v codex >/dev/null 2>&1; then
|
||||
eval "$(codex completion bash)"
|
||||
fi
|
||||
|
||||
# Function to check for TODO.md and echo its contents
|
||||
function check_todo() {
|
||||
if [ -f "TODO.md" ]; then
|
||||
echo
|
||||
echo -e "${_DIM_RED}TODO.md${_NC}"
|
||||
echo "---------------------------"
|
||||
mdcat TODO.md
|
||||
echo "---------------------------"
|
||||
echo
|
||||
fi
|
||||
if [ -f "TODO.md" ]; then
|
||||
echo
|
||||
echo -e "${_DIM_RED}TODO.md${_NC}"
|
||||
echo "---------------------------"
|
||||
if command -v mdcat >/dev/null 2>&1; then mdcat TODO.md; else cat TODO.md; fi
|
||||
echo "---------------------------"
|
||||
echo
|
||||
fi
|
||||
}
|
||||
# Function to check for .autonote.md and echo its contents
|
||||
function check_autonote() {
|
||||
if [ -f ".autonote.md" ]; then
|
||||
echo
|
||||
echo -e "${_DIM_RED}autonote.md${_NC}"
|
||||
echo "---------------------------"
|
||||
mdcat .autonote.md
|
||||
echo "---------------------------"
|
||||
echo
|
||||
fi
|
||||
if [ -f ".autonote.md" ]; then
|
||||
echo
|
||||
echo -e "${_DIM_RED}autonote.md${_NC}"
|
||||
echo "---------------------------"
|
||||
if command -v mdcat >/dev/null 2>&1; then mdcat .autonote.md; else cat .autonote.md; fi
|
||||
echo "---------------------------"
|
||||
echo
|
||||
fi
|
||||
}
|
||||
# Hook to execute check_todo, check_autonote when changing directories
|
||||
cd() {
|
||||
builtin cd "$@"
|
||||
builtin cd "$@" || return
|
||||
check_todo
|
||||
check_autonote
|
||||
}
|
||||
|
||||
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"
|
||||
check_autonote
|
||||
return 0
|
||||
}
|
||||
|
||||
# opencode
|
||||
export PATH=/home/ray/.opencode/bin:$PATH
|
||||
case ":$PATH:" in
|
||||
*":$HOME/.opencode/bin:"*) ;;
|
||||
*) export PATH="$HOME/.opencode/bin:$PATH" ;;
|
||||
esac
|
||||
|
||||
#pyenv
|
||||
export PYENV_ROOT="$HOME/.pyenv"
|
||||
export PATH="$PYENV_ROOT/bin:$PATH"
|
||||
eval "$(pyenv init -)"
|
||||
case ":$PATH:" in
|
||||
*":$PYENV_ROOT/bin:"*) ;;
|
||||
*) export PATH="$PYENV_ROOT/bin:$PATH" ;;
|
||||
esac
|
||||
if [[ -z ${PYENV_SHELL:-} ]] && command -v pyenv >/dev/null 2>&1; then
|
||||
eval "$(pyenv init -)"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -e "$HOME/.bash_profile" ] ; then
|
||||
if [ -e "$HOME/.bash_profile" ] || [ -L "$HOME/.bash_profile" ] ; then
|
||||
mv "$HOME/.bash_profile" "$HOME/bash_profile-original-$(date +%s)"
|
||||
fi
|
||||
|
||||
if [ -e "$HOME/.bashrc" ] ; then
|
||||
if [ -e "$HOME/.bashrc" ] || [ -L "$HOME/.bashrc" ] ; then
|
||||
mv "$HOME/.bashrc" "$HOME/bashrc-original-$(date +%s)"
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue