diff --git a/docs/changelog.rst b/docs/changelog.rst index 884ec99a8..5e54dfb3f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -262,6 +262,8 @@ Detailed list of changes - Linux: Workaround bug in Nvidia drivers that caused color corruption when resuming after suspend (:iss:`9844`) +- choose-files kitten: Output a trailing newline when writing to a tty in text format (:iss:`9982`) + 0.46.2 [2026-03-21] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kittens/choose_files/main.go b/kittens/choose_files/main.go index a1240ab1b..7ef92ba3e 100644 --- a/kittens/choose_files/main.go +++ b/kittens/choose_files/main.go @@ -903,6 +903,10 @@ func main(_ *cli.Command, opts *Options, args []string) (rc int, err error) { m = string(b) } os.Stdout.Write(utils.UnsafeStringToBytes(m)) + if tty.IsTerminal(os.Stdout.Fd()) && opts.OutputFormat == "text" { + // Avoid zsh's silly no trailing newline marker + os.Stdout.WriteString("\n") + } if opts.WriteOutputTo != "" { os.WriteFile(opts.WriteOutputTo, utils.UnsafeStringToBytes(m), 0600) } diff --git a/kittens/choose_files/main.py b/kittens/choose_files/main.py index d0812eeda..89ffb79f9 100644 --- a/kittens/choose_files/main.py +++ b/kittens/choose_files/main.py @@ -211,7 +211,7 @@ def handle_result(args: list[str], data: dict[str, Any], target_window_id: int, usage = '[directory to start choosing files in]' -OPTIONS = ''' +OPTIONS = """ --mode type=choices choices=file,files,save-file,dir,save-dir,dirs,save-files @@ -266,11 +266,12 @@ Path to a file to which the output is written in addition to STDOUT. --output-format choices=text,json,shell,shell-relative default=text -The format in which to write the output. The :code:`text` format is absolute paths separated by newlines. -The :code:`shell` format is quoted absolute paths separated by spaces, quoting is done only if needed. The -:code:`shell-relative` format is the same as :code:`shell` except it returns paths relative to the starting -directory. Note that when invoked from a mapping, this option is ignored, -and either text or shell format is used automatically based on whether the cursor is at a shell prompt or not. +The format in which to write the output. The :code:`text` format is absolute paths separated by newlines, +with a trailing newline. The :code:`shell` format is quoted absolute paths separated by spaces, +quoting is done only if needed. The :code:`shell-relative` format is the same as :code:`shell` except that +it returns paths relative to the starting directory. Note that when invoked from a mapping, +this option is ignored, and either text or shell format is used automatically based on whether +the cursor is at a shell prompt or not. --write-pid-to @@ -280,7 +281,7 @@ Path to a file to which to write the process ID (PID) of this process to. --clear-cache type=bool-set Clear the caches used by this kitten. -'''.format(config_help=CONFIG_HELP.format(conf_name='choose-files', appname=appname)).format +""".format(config_help=CONFIG_HELP.format(conf_name='choose-files', appname=appname)).format help_text = '''\