diff --git a/src/builtins/shared.rs b/src/builtins/shared.rs index a1b06ee5d..348441f16 100644 --- a/src/builtins/shared.rs +++ b/src/builtins/shared.rs @@ -1,7 +1,7 @@ use super::prelude::*; use crate::builtins::*; use crate::common::{escape, get_by_sorted_name, str2wcstring, Named}; -use crate::io::{IoChain, IoFd, OutputStream}; +use crate::io::{IoFd, OutputStream}; use crate::parse_constants::UNKNOWN_BUILTIN_ERR_MSG; use crate::parse_util::parse_util_argument_is_help; use crate::parser::{Block, BlockType, LoopStatus}; @@ -553,7 +553,7 @@ pub fn builtin_print_help_error( } let name_esc = escape(cmd); let mut cmd = sprintf!("__fish_print_help %ls ", &name_esc); - let mut ios = IoChain::new(); + let mut ios = streams.io_chain.clone(); if !error_message.is_empty() { cmd.push_utfstr(&escape(error_message)); // If it's an error, redirect the output of __fish_print_help to stderr diff --git a/tests/checks/print-help.fish b/tests/checks/print-help.fish new file mode 100644 index 000000000..fcd0e1327 --- /dev/null +++ b/tests/checks/print-help.fish @@ -0,0 +1,15 @@ +# RUN: %fish %s +# Test redirecting builtin help with a pipe + +set -lx __fish_data_dir (mktemp -d) +mkdir -p $__fish_data_dir/man/man1 +# Create $__fish_data_dir/man/man1/and.1 +echo '.\" Test manpage for and (not real). +.TH "AND" "1" "Feb 02, 2024" "3.7" "fish-shell" +.SH NAME +and \- conditionally execute a command' >$__fish_data_dir/man/man1/and.1 + +# help should be redirected to grep instead of appearing on STDOUT +builtin and --help | grep -q "and - conditionally execute a command" +echo $status +#CHECK: 0