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

Out-Default function breaks $? #31

Closed
chenxiaolong opened this issue Dec 21, 2019 · 7 comments
Closed

Out-Default function breaks $? #31

chenxiaolong opened this issue Dec 21, 2019 · 7 comments

Comments

@chenxiaolong
Copy link

The definition of Out-Default seems to be breaking the usage of $?.

For example, if I run an invalid command in pwsh -noprofile, I get this:

PS C:\Users\chenxiaolong> git asdf
git: 'asdf' is not a git command. See 'git --help'.

The most similar command is
        add
PS C:\Users\chenxiaolong> echo $?
False

If I import Get-ChildItemColor (version 2.1.1), then $? stops working properly:

PS C:\Users\chenxiaolong> Import-Module Get-ChildItemColor
PS C:\Users\chenxiaolong> git asdf
git: 'asdf' is not a git command. See 'git --help'.

The most similar command is
        add
PS C:\Users\chenxiaolong> echo $?
True

If I remove the Out-Default function, then things work again, but of course, no more ls colors:

PS C:\Users\chenxiaolong> Remove-Item Function:Out-Default
PS C:\Users\chenxiaolong> git asdf
git: 'asdf' is not a git command. See 'git --help'.

The most similar command is
        add
PS C:\Users\chenxiaolong> echo $?
False
chenxiaolong added a commit to chenxiaolong/dotfiles that referenced this issue Dec 22, 2019
Get-ChildItemColor overrides Out-Default in a way that breaks $?.

See: joonro/Get-ChildItemColor#31

Signed-off-by: Andrew Gunnerson <andrewgunnerson@gmail.com>
@schmjop
Copy link

schmjop commented Jul 27, 2021

I have the same issue unfortunately. @joonro is there as possible workaround?

@vdsbenoit
Copy link

I think it is related to an issue in PSColor, which Get-ChildItemColor relies on. Both projects seem to be unmaintained so I don't think this issue is going to be resolved anytime soon.

@joonro
Copy link
Owner

joonro commented Jun 7, 2022

Hi, sorry for the late response. I'm glad to let you know that I was able to fix this issue (d651f92). Now this module no longer overloads Out-Default --- instead, users should use Get-ChildItemColor. The function is now pipeline-aware (i.e., it does not touch the output when used as a part of a pipeline) and I think it should be more robust. Please let me know if this works for you.

@joonro
Copy link
Owner

joonro commented Jun 11, 2022

I will close this as this should be resolved in the latest version. Please feel free to open it again if there is still an issue.

@joonro joonro closed this as completed Jun 11, 2022
@vdsbenoit
Copy link

I confirm it's fixed on my side too! Thank you so much

@joonro
Copy link
Owner

joonro commented Jun 29, 2022

Great! Sorry it took so long to fix, but better late than never I guess :)

@vdsbenoit
Copy link

Sure! Thank you for maintaining this project, which is quite handy

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

4 participants