From 542fa9ffaef0691a3a9f4ffef65f12e22c57d849 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Mon, 13 Oct 2025 22:56:18 +0800 Subject: bump --- .../fish/functions/fish_command_not_found.fish | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 dot-config/fish/functions/fish_command_not_found.fish (limited to 'dot-config/fish/functions/fish_command_not_found.fish') diff --git a/dot-config/fish/functions/fish_command_not_found.fish b/dot-config/fish/functions/fish_command_not_found.fish new file mode 100644 index 00000000..63706737 --- /dev/null +++ b/dot-config/fish/functions/fish_command_not_found.fish @@ -0,0 +1,59 @@ +function fish_command_not_found --description "Fish: suggest/install AUR pkg when command not found" + set -l cmd $argv + set -l pkgs + + printf '\033[0;31m\033[1m==> ERROR: Command not found:\033[0m %s\n' "$cmd" + printf '\033[0m' + printf 'Checking for package.' + + # spinner: print dots until pkgfile finishes + set -l spinner_pid + fish -c ' + while true + sleep 0.1 + printf "." + end + ' & + set spinner_pid $last_pid + + # query pkgfile; -b (binaries), -v (verbose) to include repo/pkg paths + set -l out (pkgfile -b -v -- "$cmd" ^/dev/null) + + # stop spinner + kill $spinner_pid 2>/dev/null + echo + + if test -n "$out" + # Split lines into array + set pkgs $out + + printf 'The application %s is not installed. It may be found in the following AUR packages:\n' "$cmd" + for p in $pkgs + printf ' %s\n' "$p" + end + + # Emulate original logic: take second field after splitting first match by "/" + # Example line format often like: "aur/pkgname usr/bin/cmd" + set -l first $pkgs[1] + set -l parts (string split -m1 ' ' -- $first)[1] + set -l repo_pkg (string split '/' -- $parts) + set -l pkgname $repo_pkg[2] + + if test -n "$pkgname" + printf 'Do you want to Install AUR package %s? (y/N) ' "$pkgname" + read -l -n 1 choice + echo + if test (string lower -- "$choice") = y + echo "Executing command: yay -S $pkgname" + yay -S "$pkgname" --noconfirm + echo + return + else + echo + return + end + end + end 1>&2 + + return 127 +end -- cgit v1.2.3