diff options
author | Kevin Ballard <kevin@sb.org> | 2014-10-10 00:11:23 -0700 |
---|---|---|
committer | Kevin Ballard <kevin@sb.org> | 2014-10-10 00:11:23 -0700 |
commit | 76c6985f82a29422c47cdb6c72708493a6248732 (patch) | |
tree | 7b377597f61c9c2966c7664a195098db6b14726d /share | |
parent | ac8c5910eb0fa03b9384463cb2a86ac4f929362e (diff) |
A little extra tweaking so builtin_print_help looks better
The terminal width magic that __fish_print_help learned doesn't help
when builtin_print_help runs it in a subshell. Instead, add an
undocumented --tty-width flag to __fish_print_help that's used to pass
the terminal width.
Diffstat (limited to 'share')
-rw-r--r-- | share/functions/__fish_print_help.fish | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/share/functions/__fish_print_help.fish b/share/functions/__fish_print_help.fish index 46246e34..0af723ba 100644 --- a/share/functions/__fish_print_help.fish +++ b/share/functions/__fish_print_help.fish @@ -1,4 +1,11 @@ function __fish_print_help --description "Print help message for the specified fish function or builtin" --argument item + # special support for builtin_help_get() + set -l tty_width + if test "$item" = "--tty-width" + set tty_width $argv[2] + set item $argv[3] + end + if test "$item" = '.' set item source end @@ -12,19 +19,23 @@ function __fish_print_help --description "Print help message for the specified f # Render help output, save output into the variable 'help' set -l help + set -l cols set -l rLL - if command test -t 1 + if test "$tty_width" -gt 0 + set cols $tty_width + else if command test -t 1 # We want to simulate `man`'s dynamic line length, because # defaulting to 80 kind of sucks. # Note: using `command test` instead of `test` because `test -t 1` # doesn't seem to work right. # Note: grab the size from the stdout terminal in case it's somehow # different than the stdin of fish. - set -l cols + # use fd 3 to copy our stdout because we need to pipe the output of stty begin - # use fd 3 to copy our stdout because we need to pipe the output of stty stty size 0<&3 | read _ cols end 3<&1 + end + if test -n "$cols" set cols (expr $cols - 4) # leave a bit of space on the right set rLL -rLL=$cols[1]n end |