Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output exa results differently in scripting environment with grid options #1083

Open
Zhengqbbb opened this issue Jul 8, 2022 · 6 comments
Open

Comments

@Zhengqbbb
Copy link

Zhengqbbb commented Jul 8, 2022

If exa does something unexpected, or its output looks wrong, or it displays an error on the screen, or if it outright crashes, then please include the following information in your report:

  • The version of exa being used (exa --version)
  • The command-line arguments you are using
  • Your operating system and hardware platform

If it’s a crash, please include the full text of the crash that gets printed to the screen. If you’re seeing unexpected behaviour, a screenshot of the issue will help a lot.


  • exa --version: v0.10.1
  • System:
    OS: macOS 12.0.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 24.61 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh

In scripting environment. I hope to be able to record the output of exa completely, but as you can see, it is output in oneline form, but I have specified my options --grid but it doesn't seem to take effect.

image

Reproduce:

a="$(exa --color=always --grid)"
printf "%s\n" "$a"

printf "%s\n" ""

exa --color=always --grid

Guess: whether with [ -t 1 ] is forced output processing

@dylan-tock
Copy link

Experiencing the same issue.

image

And here's the script, output, and system/software details:

workstation> cat a.sh
#!/usr/bin/zsh

printf "== Inside subshell\n"
a="$(exa --color=always --grid)"
printf "%s\n" "$a"

printf "%s\n" ""

printf "== Plain command\n"
exa --color=always --grid

printf "%s\n" ""

printf "== Inside subshell with COLUMNS variable explicitly set\n"
a="$(COLUMNS="${COLUMNS}" exa --color=always --grid)"
printf "%s\n" "$a"

printf "%s\n" ""

workstation> ./a.sh
== Inside subshell
a
a.sh
b

== Plain command
a  a.sh  b

== Inside subshell with COLUMNS variable explicitly set
a  a.sh  b

workstation> exa --version
exa - list files on the command-line
v0.10.1 [+git]
https://the.exa.website/
workstation> uname -a
Linux workstation 5.15.0-1032-gcp #40~20.04.1-Ubuntu SMP Tue Apr 11 02:49:52 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
workstation> zsh --version
zsh 5.8 (x86_64-ubuntu-linux-gnu)
workstation>

This root cause might be the same as what's reported in issue 990.

@ariasuni
Copy link
Collaborator

ariasuni commented Sep 7, 2023

Does it still happen with latest master, or with [the active fork eza)[https://github.com/eza-community/eza]?

@dylan-tock
Copy link

image

Doing compare and contrast of exa and eza for completeness' sake. Here's the updated script contents. The rest of the data is the same as my previous comment.

#!/usr/bin/zsh

runTest() {
  echo "======= DONE WITH TEST OF ${EXA} ======="
  ${EXA} --version
  echo ""
  printf "== Inside subshell\n"
  a="$(${EXA} --color=always --grid)"
  printf "%s\n" "$a"

  printf "%s\n" ""

  printf "== Plain command\n"
  ${EXA} --color=always --grid

  printf "%s\n" ""

  printf "== Inside subshell with COLUMNS variable explicitly set\n"
  a="$(COLUMNS="${COLUMNS}" ${EXA} --color=always --grid)"
  printf "%s\n" "$a"

  printf "%s\n" ""
  echo "======= DONE WITH TEST OF ${EXA} ======="
}

EXA='exa'
runTest
EXA='eza'
runTest

@ariasuni
Copy link
Collaborator

ariasuni commented Sep 8, 2023

Hum thinking about it, I don’t think it’s wrong. I believe In a script, exa doesn’t know about the number of columns of the terminal, or because it’s easier to treat output line by line in scripts. Besides, it’s also the behavior of ls, so in that regards it can be considered correct, at least by default.

@Zhengqbbb
Copy link
Author

Zhengqbbb commented Sep 8, 2023

@ariasuni Hum thinking about it, I don’t think it’s wrong. I believe In a script, exa doesn’t know about the number of columns of the terminal, or because it’s easier to treat output line by line in scripts. Besides, it’s also the behavior of ls, so in that regards it can be considered correct, at least by default.

I understand your point. In fact, it's normal to handle "array" behavior line by line in a script environment.

However, In my opinion the CLI provides this option and a user uses it, but the resulting behavior is not as expected, it could lead to the script becoming ineffective and unreasonable.

It's like --color --no-color --force-color option. The CLI can have default hander behavior. And if with the option, the behavior should be change.

@ariasuni
Copy link
Collaborator

ariasuni commented Sep 8, 2023

Ah I see, so when passing --grid explicitly, you’d like exa to display as a grid even in subshells. It seems to be possible with any_terminal_size, but it’s not trivial in the code to determine if the flag has been passed explicitly or not. Maybe I could implement this in eza when this PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants