Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast and functional replacement for __fish_describe_command for Macos #7365

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions share/functions/__fish_describe_command.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,25 @@
# The whatis database is non-existent, so apropos tries (and fails) to create it every time,
# which takes about half a second.
#
# So we disable this entirely in that case.
if test (uname) = Darwin
set -l darwin_version (uname -r | string split .)
# macOS 15 is Darwin 19, this is an issue up to and including 10.15.3.
if test "$darwin_version[1]" = 19 -a "$darwin_version[2]" -le 3
function __fish_describe_command
# Instead, we build a whatis database in the user home directory
# and use grep to query it
#
# A function `__fish_apropos_update` is provided for updating
#
function __fish_apropos -d "Internal command to query the apopos database"
if test (uname) = Darwin
folke marked this conversation as resolved.
Show resolved Hide resolved
set db ~/.whatis.db
folke marked this conversation as resolved.
Show resolved Hide resolved

function __fish_apropos_update -d "Updates the apropos database $db on Macos"
echo "updating apropos / whatis database at $db"
folke marked this conversation as resolved.
Show resolved Hide resolved
man --path | tr ":" " " | xargs /usr/libexec/makewhatis -o $db
folke marked this conversation as resolved.
Show resolved Hide resolved
end
# (remember: exit when `source`ing only exits the file, not the shell)
exit

[ -f $db ] || __fish_apropos_update
folke marked this conversation as resolved.
Show resolved Hide resolved

/usr/bin/grep -i "$argv" $db
folke marked this conversation as resolved.
Show resolved Hide resolved
else
apropos $argv
end
end

Expand All @@ -28,7 +38,7 @@ end
function __fish_describe_command -d "Command used to find descriptions for commands"
# $argv will be inserted directly into the awk regex, so it must be escaped
set -l argv_regex (string escape --style=regex "$argv")
apropos $argv 2>/dev/null | awk -v FS=" +- +" '{
__fish_apropos $argv 2>/dev/null | awk -v FS=" +- +" '{
split($1, names, ", ");
for (name in names)
if (names[name] ~ /^'"$argv_regex"'.* *\([18]\)/ ) {
Expand Down