48 lines
1.8 KiB
Diff
48 lines
1.8 KiB
Diff
--- a/share/functions/fish_command_not_found.fish
|
|
+++ b/share/functions/fish_command_not_found.fish
|
|
@@ -49,6 +49,44 @@
|
|
function fish_command_not_found
|
|
command-not-found -- $argv[1]
|
|
end
|
|
+ # depot can query binary repo metadata for path ownership, which lets us
|
|
+ # suggest packages for missing commands in a pkgfile-like format.
|
|
+else if type -q depot
|
|
+ function fish_command_not_found
|
|
+ set -l __depot_seen_dirs
|
|
+ set -l __depot_paths
|
|
+ set -l __depot_packages
|
|
+
|
|
+ for __dir in $PATH
|
|
+ string match -q '/*' -- $__dir; or continue
|
|
+ contains -- $__dir $__depot_seen_dirs; and continue
|
|
+ set -a __depot_seen_dirs $__dir
|
|
+ set -a __depot_paths $__dir/$argv[1]
|
|
+ end
|
|
+
|
|
+ if test (count $__depot_paths) -eq 0
|
|
+ set __depot_paths /usr/bin/$argv[1] /bin/$argv[1]
|
|
+ end
|
|
+
|
|
+ for __path in $__depot_paths
|
|
+ set -l __hits (
|
|
+ depot repo owns $__path 2>/dev/null |
|
|
+ string match -r '^\[INFO\] [^ ]+ \[binary:[^]]+\] [^ ]+ size=[^ ]+ owns=.*$' |
|
|
+ string replace -r '^\[INFO\] ([^ ]+) \[binary:([^]]+)\] ([^ ]+) size=[^ ]+ owns=(.+)$' '$2/$1 $3\t$4'
|
|
+ )
|
|
+
|
|
+ for __hit in $__hits
|
|
+ contains -- $__hit $__depot_packages; or set -a __depot_packages $__hit
|
|
+ end
|
|
+ end
|
|
+
|
|
+ if test (count $__depot_packages) -gt 0
|
|
+ printf "%s may be found in the following packages:\n" "$argv[1]"
|
|
+ printf " %s\n" $__depot_packages
|
|
+ else
|
|
+ __fish_default_command_not_found_handler $argv[1]
|
|
+ end
|
|
+ end
|
|
# pkgfile is an optional, but official, package on Arch Linux
|
|
# it ships with example handlers for bash and zsh, so we'll follow that format
|
|
else if type -q pkgfile
|