From 40d772fde377e94a527f6394b0afdeb154d84f1c Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 14 Oct 2025 01:31:10 +0200 Subject: [PATCH] share: share logic between standalone and installed builds --- share/functions/__fish_complete_man.fish | 5 ++-- share/functions/__fish_print_commands.fish | 6 +---- share/functions/__fish_print_help.fish | 31 +++++++++------------- share/functions/man.fish | 23 +++++++--------- 4 files changed, 24 insertions(+), 41 deletions(-) diff --git a/share/functions/__fish_complete_man.fish b/share/functions/__fish_complete_man.fish index 5b7a84168..2bbcfc4f3 100644 --- a/share/functions/__fish_complete_man.fish +++ b/share/functions/__fish_complete_man.fish @@ -70,9 +70,8 @@ function __fish_complete_man # Fish commands are not given by apropos if not set -ql exclude_fish_commands - set -l files $__fish_data_dir/man/man1/*.1* - string replace -r '.*/([^/]+)\.1(\.gz)?$' '$1\t1: fish command' \ - -- $files (status list-files man/man1/ 2>/dev/null) + __fish_data_list_files man/man1 | + string replace -rf '.*/([^/]+)\.1(\.gz)?$' '$1\t1: fish command' end else return 1 diff --git a/share/functions/__fish_print_commands.fish b/share/functions/__fish_print_commands.fish index 0d2112eec..319c112be 100644 --- a/share/functions/__fish_print_commands.fish +++ b/share/functions/__fish_print_commands.fish @@ -1,10 +1,6 @@ # localization: skip(private) function __fish_print_commands --description "Print a list of documented fish commands" - if set -q __fish_data_dir[1] && test -d $__fish_data_dir/man/man1/ - printf %s\n $__fish_data_dir/man/man1/**.1* - else - status list-files man/man1/ 2>/dev/null - end | + __fish_data_list_files man/man1 | string replace -r '.*/' '' | string replace -r '.1(.gz)?$' '' | string match -rv '^fish-(?:changelog|completions|doc|tutorial|faq|for-bash-users|interactive|language|releasenotes|terminal-compatibility)$' diff --git a/share/functions/__fish_print_help.fish b/share/functions/__fish_print_help.fish index 56a809864..1b2da1351 100644 --- a/share/functions/__fish_print_help.fish +++ b/share/functions/__fish_print_help.fish @@ -19,26 +19,19 @@ function __fish_print_help --description "Print help for the specified fish func return end - # NOTE: this is duplicated with share/functions/man.fish, but that - # function is not always defined. - set -l tmpdir - set -l file (path filter -- \ - $__fish_data_dir/man/man1/$item.1 \ - $__fish_data_dir/man/man1/$item.1.gz) - or begin - set -l contents "$(status get-file man/man1/$item.1)" - or return 2 - set tmpdir (__fish_mktemp_relative -d fish-print-help) - or return - set file $tmpdir/$item.1 - printf %s\n $contents >$file + function __fish_print_help_man -V item -a man1 + if not path is $man1 + # Trigger the "documentation not be installed" message. Currently + # only when called from core. + return 2 + end + set -l file (path filter -- $man1/$item.1 $man1/$item.1.gz) + command man $file[1] end - command man $file[1] - set -l saved_status $status - if set -q tmpdir[1] - command rm -r $tmpdir - end - return $saved_status + __fish_data_with_directory man/man1 \ + "$(string escape --style=regex $item.1)(?:\.gz)?" \ + __fish_print_help_man + __fish_with_status functions --erase __fish_print_help_man end function __fish_print_help_pre_4.1 --description "Print help message for the specified fish function or builtin" diff --git a/share/functions/man.fish b/share/functions/man.fish index a88bc4bef..e38a480b5 100644 --- a/share/functions/man.fish +++ b/share/functions/man.fish @@ -57,20 +57,15 @@ function man end end - set -l tmpdir if not set -q argv[2] && status list-files "man/man1/$argv[1].1" &>/dev/null - set tmpdir (__fish_mktemp_relative -d fish-man) - or return - status get-file "man/man1/$argv[1].1" >$tmpdir/$argv.1 - set argv $tmpdir/$argv.1 + set -l basename $argv[1].1 + function __fish_man -V basename -a man1 + command man $man1/$basename + end + __fish_data_with_directory man/man1 \ + (string escape --style=regex -- $basename) __fish_man + __fish_with_status functions --erase __fish_man + else + command man $argv end - - command man $argv - set -l saved_status $status - - if set -q tmpdir[1] - command rm -r $tmpdir - end - - return $saved_status end