mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 04:58:57 +00:00
Add __fish_whatis helper function/wrapper for whatis
Executes `whatis` safely, returns at most one line, and strips the name of the command from the start of line, returning a value fit for use as the description parameter for a completion argument value.
This commit is contained in:
parent
8e49229d8f
commit
948b9d2ab8
1 changed files with 21 additions and 0 deletions
21
share/functions/__fish_whatis.fish
Normal file
21
share/functions/__fish_whatis.fish
Normal file
|
@ -0,0 +1,21 @@
|
|||
# uses `whatis` if available to describe a command
|
||||
|
||||
function __fish_whatis
|
||||
set -l cmd $argv[1]
|
||||
set -l fallback
|
||||
if set -q argv[2]
|
||||
set fallback $argv[2]
|
||||
end
|
||||
|
||||
set -l description (whatis $cmd 2>/dev/null | string replace -r '.*? - ' '')[1]
|
||||
if not string match -qr -- "$description" "."
|
||||
printf '%s\n' $description
|
||||
return 0
|
||||
else if not string match -q -- "$fallback" ""
|
||||
printf '%s\n' $fallback
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in a new issue