From acf9555a4bfcaee9f5b2f4d5ab1d895dab9dae43 Mon Sep 17 00:00:00 2001 From: Hadi Chokr Date: Wed, 13 May 2026 09:34:08 +0200 Subject: [PATCH] lol --- .../usr/lib/command-not-found-handler.py | 2 - .../kde-linux-default-zshrc.zsh | 6 ++ .../kde-linux-default/kde-linux-du.zsh | 69 +++++++++++++++++++ mkosi.finalize.d/40-core.sh.chroot | 3 - 4 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 mkosi.extra/usr/share/zsh/plugins/kde-linux-default/kde-linux-du.zsh diff --git a/mkosi.extra/usr/lib/command-not-found-handler.py b/mkosi.extra/usr/lib/command-not-found-handler.py index c7e4233..a85bf5b 100755 --- a/mkosi.extra/usr/lib/command-not-found-handler.py +++ b/mkosi.extra/usr/lib/command-not-found-handler.py @@ -17,7 +17,6 @@ known_alternatives = { "arp" : "ip neigh", "cron" : "systemctl list-timers", "dig" : "resolvectl query", - "du" : "btrfs filesystem du", "egrep" : "rg", "fgrep" : "rg -F", "hostname" : "hostnamectl", @@ -28,7 +27,6 @@ known_alternatives = { "iptunnel" : "ip tunnel", "iwconfig" : "iw", "nameif" : "ip link", - "ncdu" : "btrfs filesystem du", "netstat" : "ss", "nslookup" : "resolvectl query", "route" : "ip route", diff --git a/mkosi.extra/usr/share/zsh/plugins/kde-linux-default/kde-linux-default-zshrc.zsh b/mkosi.extra/usr/share/zsh/plugins/kde-linux-default/kde-linux-default-zshrc.zsh index ce34d39..f899427 100644 --- a/mkosi.extra/usr/share/zsh/plugins/kde-linux-default/kde-linux-default-zshrc.zsh +++ b/mkosi.extra/usr/share/zsh/plugins/kde-linux-default/kde-linux-default-zshrc.zsh @@ -118,3 +118,9 @@ source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring # Bind Ctrl+↑ and Ctrl+↓ keybinds to substring history search. bindkey '^[[1;5A' history-substring-search-up # Ctrl+↑ bindkey '^[[1;5B' history-substring-search-down # Ctrl+↓ + +# Source additional configuration files from this plugin directory. +for f in /usr/share/zsh/plugins/kde-linux-default/*.zsh; do + [[ "$f" == "${(%):-%x}" ]] && continue + source "$f" +done \ No newline at end of file diff --git a/mkosi.extra/usr/share/zsh/plugins/kde-linux-default/kde-linux-du.zsh b/mkosi.extra/usr/share/zsh/plugins/kde-linux-default/kde-linux-du.zsh new file mode 100644 index 0000000..fe07be9 --- /dev/null +++ b/mkosi.extra/usr/share/zsh/plugins/kde-linux-default/kde-linux-du.zsh @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +# SPDX-FileCopyrightText: 2026 Hadi Chokr + +# On btrfs systems, wrap du to use btrfs fi du for accurate disk usage reporting. +# Falls back to system du for unsupported flags or non-btrfs paths. +function du() { + # Whitelist of flags supported by btrfs fi du + # Any unrecognised flag falls back to system du + local arg + for arg in "$@"; do + case "$arg" in + --) break ;; + -s|--summarize|\ + --raw|\ + --human-readable|\ + --iec|\ + --si|\ + --kbytes|\ + --mbytes|\ + --gbytes|\ + --tbytes) ;; + -*) + command du "$@" + return + ;; + esac + done + + # Parse opts and paths, respecting -- + local opts=() + local file_paths=() + local end_of_opts=false + + while [[ $# -gt 0 ]]; do + if [[ "$end_of_opts" == false && "$1" == "--" ]]; then + end_of_opts=true + shift + elif [[ "$end_of_opts" == false && "$1" == -* ]]; then + opts+=("$1") + shift + else + file_paths+=("$1") + shift + fi + done + + # Fall back to system du if no paths given + if [[ ${#file_paths[@]} -eq 0 ]]; then + command du "${opts[@]}" + return + fi + + # Check all paths are on btrfs + local can_use_btrfs=true + for path in "${file_paths[@]}"; do + local fs + fs="$(findmnt -n -o FSTYPE --target "$path" 2>/dev/null)" + if [[ "$fs" != "btrfs" ]]; then + can_use_btrfs=false + break + fi + done + + if [[ "$can_use_btrfs" == true ]]; then + btrfs fi du "${opts[@]}" "${file_paths[@]}" + else + command du "${opts[@]}" "${file_paths[@]}" + fi +} \ No newline at end of file diff --git a/mkosi.finalize.d/40-core.sh.chroot b/mkosi.finalize.d/40-core.sh.chroot index b59ea83..45ce748 100755 --- a/mkosi.finalize.d/40-core.sh.chroot +++ b/mkosi.finalize.d/40-core.sh.chroot @@ -65,9 +65,6 @@ rm -rf \ /usr/bin/qvidcap \ /usr/share/applications/qvidcap.desktop \ -# Use the btrfs versions instead as in command_not_found_handle -rm -rf du \ - # Parts of plasma-sdk that are on Flathub now, so you can just get them from there # (once everything is on Flathub, we can stop building plasma-sdk, and remove these lines) rm -rf \