summaryrefslogtreecommitdiff
path: root/dot-config/fish/functions/fish_command_not_found.fish
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-10-13 22:56:18 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-10-13 22:58:22 +0800
commit542fa9ffaef0691a3a9f4ffef65f12e22c57d849 (patch)
treee3f56a823778188e418eeec2642d5785d3ae3c0e /dot-config/fish/functions/fish_command_not_found.fish
parent0c7001019bb345d59892de88c355b653d2680fdb (diff)
bump
Diffstat (limited to 'dot-config/fish/functions/fish_command_not_found.fish')
-rw-r--r--dot-config/fish/functions/fish_command_not_found.fish59
1 files changed, 59 insertions, 0 deletions
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