From b71910cf51eb848c43e527562c7e23b695d37629 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Sat, 20 Sep 2025 15:11:25 +1000 Subject: [PATCH] Update `CHANGELOG.md` and some cleanup (#2176) --- CHANGELOG.md | 4 ++++ app.go | 26 ++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb06e7e4..c1dd98e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - A new command `cmd-menu-discard` is added to allow exiting the completion menu with completions discarded (#2146). - The `lf_mode` environment variable will now be set to `compmenu` if the completion menu is active (#2146). +### Fixed + +- `shell-pipe` commands no longer wait for output if kept open after the command has finished running (#2155). + ## [r38](https://github.com/gokcehan/lf/releases/tag/r38) ### Changed diff --git a/app.go b/app.go index cc021ac9..1b360722 100644 --- a/app.go +++ b/app.go @@ -583,23 +583,24 @@ func (app *app) runShell(s string, args []string, prefix string) { } // We are running the command asynchronously - var inReader, outReader, outWriter *os.File - var err error + var inReader, inWriter, outReader, outWriter *os.File if prefix == "%" { if app.ui.cmdPrefix == ">" { return } - // Hook up stdin and stdout. - // We don't use Cmd.StdoutPipe and friends because its docs say - // "It is … incorrect to call Wait before all reads from the pipe have completed." - // (see also https://github.com/golang/go/issues/60908). - // But we are going to be calling Wait concurrently with reading from the stdout pipe. - inReader, app.cmdIn, err = os.Pipe() + + // Cmd.StdoutPipe cannot be used as it requires the output to be fully + // read before calling Cmd.Wait, however in this case Cmd.Wait should + // only wait for the command to finish executing regardless of whether + // the output has been fully read or not. + inReader, inWriter, err := os.Pipe() if err != nil { log.Printf("creating input pipe: %s", err) return } cmd.Stdin = inReader + app.cmdIn = inWriter + outReader, outWriter, err = os.Pipe() if err != nil { log.Printf("creating output pipe: %s", err) @@ -610,7 +611,7 @@ func (app *app) runShell(s string, args []string, prefix string) { } shellSetPG(cmd) - if err = cmd.Start(); err != nil { + if err := cmd.Start(); err != nil { app.ui.echoerrf("running shell: %s", err) } @@ -648,10 +649,11 @@ func (app *app) runShell(s string, args []string, prefix string) { if err := cmd.Wait(); err != nil { log.Printf("running shell: %s", err) } - outWriter.Close() - outReader.Close() - app.cmdIn.Close() inReader.Close() + inWriter.Close() + outReader.Close() + outWriter.Close() + app.cmd = nil app.ui.cmdPrefix = "" app.ui.exprChan <- &callExpr{"load", nil, 1}