This commit is contained in:
Hadi Chokr
2026-05-13 09:34:08 +02:00
parent 2d0e5491ce
commit acf9555a4b
4 changed files with 75 additions and 5 deletions

View File

@@ -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",

View File

@@ -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

View File

@@ -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 <hadichokr@icloud.com>
# 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
}

View File

@@ -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 \