2006-11-17 16:24:38 +00:00
|
|
|
|
2007-09-23 21:07:30 +00:00
|
|
|
function __fish_print_help --description "Print help message for the specified fish function or builtin" --argument item
|
2007-09-22 22:38:28 +00:00
|
|
|
|
|
|
|
switch $argv[1]
|
|
|
|
case '.'
|
|
|
|
set item source
|
|
|
|
|
|
|
|
case '*'
|
|
|
|
set item $argv[1]
|
|
|
|
end
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2012-09-01 09:14:13 +00:00
|
|
|
# Do nothing if the file does not exist
|
|
|
|
if not test -e "$__fish_datadir/man/man1/$item.1"
|
|
|
|
return
|
|
|
|
end
|
2007-09-22 22:38:28 +00:00
|
|
|
|
2006-11-19 23:27:34 +00:00
|
|
|
# These two expressions take care of underlines (Should be italic)
|
|
|
|
set -l cmd1 s/_\x08'\(.\)'/(set_color --underline)\\1(set_color normal)/g
|
|
|
|
set -l cmd2 s/'\(.\)'\x08_/(set_color --underline)\\1(set_color normal)/g
|
|
|
|
|
|
|
|
# This expression should take care of bold characters. It's not
|
2006-11-20 13:14:12 +00:00
|
|
|
# waterproof, since it doesn't check that the same character is
|
|
|
|
# used both before and after the backspace, since regular
|
|
|
|
# languages don't allow backreferences.
|
2006-11-19 23:27:34 +00:00
|
|
|
set -l cmd3 s/.\x08'\(.\)'/(set_color --bold)\\1(set_color normal)/g
|
|
|
|
|
|
|
|
# Combine all expressions in a single variable
|
2010-09-18 02:18:26 +00:00
|
|
|
set -l sed_cmd -e $cmd1 -e $cmd2 -e $cmd3
|
2006-11-19 23:27:34 +00:00
|
|
|
|
|
|
|
# Render help output, save output into the variable 'help'
|
2012-07-06 23:31:06 +00:00
|
|
|
set -l help (nroff -man "$__fish_datadir/man/man1/$item.1" ^ /dev/null )
|
2006-11-17 16:24:38 +00:00
|
|
|
set -l lines (count $help)
|
2006-11-19 23:27:34 +00:00
|
|
|
|
|
|
|
# Print an empty line first
|
2006-11-17 16:24:38 +00:00
|
|
|
echo
|
2006-11-19 23:27:34 +00:00
|
|
|
|
|
|
|
# Filter and print help
|
2006-11-20 13:14:12 +00:00
|
|
|
printf "%s\n" $help| tail -n (expr $lines - 5) | head -n (expr $lines - 8) | sed $sed_cmd
|
2006-11-19 23:27:34 +00:00
|
|
|
|
2012-09-01 09:14:13 +00:00
|
|
|
end
|