function chkupd --description '自動檢查套件可更新數量(每日首次自動同步,後續快速檢查)' set -l state_dir "$HOME/.local/state/chkupd" set -l sync_date_file "$state_dir/last_sync_date" # 將檢查狀態存入檔案
test -d $state_dir; or mkdir -p $state_dir
set -l today (date +%Y%m%d) set -l last_sync (cat $sync_date_file 2>/dev/null) set -l sync_opt -n set -l os (grep PRETTY_NAME /etc/os-release | cut -d'"' -f2 | sed 's/Linux//g')
if test "$argv[1]" = sync -o "$last_sync" != "$today" set sync_opt "" echo $today >$sync_date_file end
# 1. 檢查 Arch/CachyOS/Artix (使用 Arch 系應該都有的 checkupdate) if command -v checkupdates >/dev/null set -l a_count (checkupdates 2>/dev/null | count)
if test $a_count -gt 0 echo "$os 套件更新數量: $a_count" notify-send "套件更新提醒" "$os 套件更新數量: $a_count" end end
# 2. 檢查 AUR (使用 paru -Qua 或 yay -Qua) set -l a2_count 0 if command -v paru >/dev/null or command -v yay >/dev/null if command -v paru >/dev/null set a2_count (paru -Qua 2>/dev/null | count) end
if command -v yay >/dev/null set a2_count (yay -Qua 2>/dev/null | count) end
if test $a2_count -gt 0 echo "AUR 套件更新數量: $a2_count" notify-send "套件更新提醒" "AUR 套件更新數量: $a2_count" end end
# 3. 檢查 Flatpak if command -v flatpak >/dev/null set -l f_count (flatpak remote-ls --updates 2>/dev/null | count)
if test $f_count -gt 0 echo "Flatpak 套件更新數量: $f_count" notify-send "套件更新提醒" "Flatpak 套件更新數量: $f_count" end end end