bat icon indicating copy to clipboard operation
bat copied to clipboard

Not have syntax highlight from stdin after pipe in nushell

Open ghost opened this issue 1 year ago • 2 comments

What steps will reproduce the bug?

  1. Using nushell
  2. Write command: `echo "#include <stdio.h>" | bat -l c

What happens?

The output in plain text instead of highlight

What did you expect to happen instead?

The output appears with highlight format

How did you install bat?

apt-get


bat version and environment bat 0.24.0 nushell 0.88.0

❯ echo "#include <stdio.h>" | bat -l c --diagnostic

Software version

bat 0.24.0

Operating system

Linux 5.4.0-107-generic

Command-line

bat -l c --diagnostic 

Environment variables

SHELL=/usr/bin/zsh
PAGER=<not set>
LESS=<not set>
LANG=en_US.UTF-8
LC_ALL=<not set>
BAT_PAGER=<not set>
BAT_PAGING=<not set>
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
XDG_CONFIG_HOME=<not set>
XDG_CACHE_HOME=<not set>
COLORTERM=truecolor
NO_COLOR=<not set>
MANPAGER=<not set>

System Config file

Could not read contents of '/etc/bat/config': No such file or directory (os error 2).

Config file

Could not read contents of '/home/havata/.config/bat/config': No such file or directory (os error 2).

Custom assets metadata

Could not read contents of '/home/havata/.cache/bat/metadata.yaml': No such file or directory (os error 2).

Custom assets

'/home/havata/.cache/bat' not found

Compile time information

  • Profile: release
  • Target triple: x86_64-unknown-linux-gnu
  • Family: unix
  • OS: linux
  • Architecture: x86_64
  • Pointer width: 64
  • Endian: little
  • CPU features: fxsr,sse,sse2
  • Host: x86_64-unknown-linux-gnu

Less version

> less --version 
less 487 (GNU regular expressions)
Copyright (C) 1984-2016  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less

ghost avatar Dec 21 '23 16:12 ghost

Does this issue still occur? Unfortunately, I'm not able to reproduce it on either MacOS or Arch Linux using the latest version of nushell.

If it does, are you able to determine if nushell has the STDOUT file descriptor of the echo "#include <stdio.h>" | bat -l c command connected to a terminal? Try adding | test -t 1 to the end and printing the exit code of test. If it's a terminal, it will exit with 0.

The only time bat will behave like cat (not applying any color or decorations) is when it's being piped to another command. It determines that by checking to see if STDOUT is not a terminal, which is where I suspect the issue may be.

eth-p avatar Feb 08 '24 02:02 eth-p