update
This commit is contained in:
parent
7a97c460d8
commit
c3c680ecca
11 changed files with 364 additions and 356 deletions
90
bashrc.d/40-status.bash
Normal file
90
bashrc.d/40-status.bash
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
# shellcheck shell=bash
|
||||
|
||||
_mem_available=$(awk '/MemAvailable/ { printf "%.1f \n", $2/1024/1024 }' /proc/meminfo)
|
||||
_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
|
||||
|
||||
if declare -F _command_reminder >/dev/null 2>&1; then
|
||||
printf '%s\n' 'Remember commands:'
|
||||
printf '%b' "$_WHITE"
|
||||
_command_reminder
|
||||
printf '%b\n\n' "$_NC"
|
||||
fi
|
||||
|
||||
if [[ ${_mem_available%.*} -lt 5 ]]; then
|
||||
printf 'Memory available: %b' "$_YELLOW"
|
||||
[[ ${_mem_available%.*} -lt 3 ]] && printf '%b' "$_RED"
|
||||
printf '%sGB%b\n' "$_mem_available" "$_NC"
|
||||
fi
|
||||
|
||||
if [[ $_updates_available -gt 0 ]]; then
|
||||
update_color="$_BRIGHT_WHITE"
|
||||
if [[ $_updates_available -gt 29 ]]; then
|
||||
update_color="$_RED"
|
||||
elif [[ $_updates_available -gt 15 ]]; then
|
||||
update_color="$_YELLOW"
|
||||
fi
|
||||
printf 'Updates available: %b%s%b [ update with: %bupdate%b ]\n' \
|
||||
"$update_color" "$_updates_available" "$_NC" "$update_color" "$_NC"
|
||||
fi
|
||||
|
||||
if [[ $_orphans_available -gt 0 ]]; then
|
||||
orphan_color="$_BRIGHT_WHITE"
|
||||
if [[ $_orphans_available -gt 9 ]]; then
|
||||
orphan_color="$_RED"
|
||||
elif [[ $_orphans_available -gt 4 ]]; then
|
||||
orphan_color="$_YELLOW"
|
||||
fi
|
||||
printf 'Orphaned packages: %b%s%b [ remove with: %bsudo pacman -Rns $(pacman -Qdtq)%b ]\n' \
|
||||
"$orphan_color" "$_orphans_available" "$_NC" "$orphan_color" "$_NC"
|
||||
fi
|
||||
|
||||
printf '\nRemember "%bTODO.md%b" (%bet%b) and "%bautonote.md%b" (%bea%b) files have content automatically displayed.\n\n' \
|
||||
"$_BLUE" "$_NC" "$_BLUE" "$_NC" "$_BLUE" "$_NC" "$_BLUE" "$_NC"
|
||||
|
||||
unset _mem_available _updates_available _orphans_available update_color orphan_color
|
||||
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 _package_status_now
|
||||
unset _package_status_current_pacman_log_signature _package_status_key _package_status_value
|
||||
Loading…
Add table
Add a link
Reference in a new issue