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

Fix out of scope opt variable #10020

Merged
merged 2 commits into from Oct 7, 2023
Merged

Conversation

mathijshenquet
Copy link
Contributor

Description

I had a weird bug on a fresh fish install and I traced it back to this rather weird piece of code. The $opt variable is not set when the if at L29 fails and so just contained random junk from an earlier function call. Moreover, with every subsequent call of of ls it would grow an extra -F! I believe the following is the intended meaning of the author.

You can look at the blame of linet 53 and 66 to see that this state of things was caused by an old refactor of the ls function.

Fixes issue: if $opt is filled with some junk before calling ls it will result in unexpected behavior

~> set fish_trace on
~> set opt test

set opt test
~> ls
ls
(...)
--> ls --color=auto test -F
ls: cannot access 'test': No such file or directory

@@ -50,7 +50,6 @@ function ls --description "List contents of directory"
__fish_set_lscolors

isatty stdout
Copy link
Member

@faho faho Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention is to apply -F only if the output goes to the terminal. Your patch removes that and makes this isatty ineffectual.

The simplest fix is to set $opt before:

set -l opt
isatty stdout
and set opt -F

Note that we have some cases above where we might apply "-F" even if the output isn't a tty, those should be removed. It's either when we have colorls or when ls doesn't support any of the color flags.

@faho faho added the bug Something that's not working as intended label Sep 15, 2023
@faho faho added this to the fish 3.7.0 milestone Sep 15, 2023
@faho faho merged commit a809672 into fish-shell:master Oct 7, 2023
6 of 7 checks passed
@faho
Copy link
Member

faho commented Oct 7, 2023

Thanks!

faho pushed a commit that referenced this pull request Oct 8, 2023
* Fix out of scope opt variable

* Update ls.fish

(cherry picked from commit a809672)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that's not working as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants