2018-06-28 03:11:57 +08:00
|
|
|
# uses `whatis` if available to describe a command
|
|
|
|
|
|
|
|
function __fish_whatis
|
2019-05-05 18:09:25 +08:00
|
|
|
set -l cmd $argv[1]
|
|
|
|
set -l fallback
|
|
|
|
if set -q argv[2]
|
|
|
|
set fallback $argv[2]
|
|
|
|
end
|
2018-06-28 03:11:57 +08:00
|
|
|
|
2019-05-05 18:09:25 +08:00
|
|
|
set -l description (whatis $cmd 2>/dev/null | string replace -r '.*? - ' '')[1]
|
2024-06-25 03:25:17 +08:00
|
|
|
if string match -qr -- "." "$description"
|
2019-05-05 18:09:25 +08:00
|
|
|
printf '%s\n' $description
|
|
|
|
return 0
|
|
|
|
else if not string match -q -- "$fallback" ""
|
|
|
|
printf '%s\n' $fallback
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
end
|
2018-06-28 03:11:57 +08:00
|
|
|
end
|