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

installscripts command fails in PowerShell #421

Closed
rashil2000 opened this issue Feb 4, 2023 · 5 comments
Closed

installscripts command fails in PowerShell #421

rashil2000 opened this issue Feb 4, 2023 · 5 comments
Labels
external The issue is due to external causes outside of Clink

Comments

@rashil2000
Copy link
Contributor

rashil2000 commented Feb 4, 2023

This is related to the Scoop manifest for clink-completions, which uses the clink installscripts ... command.

It used to work perfectly fine, but now when using this command in PowerShell, this error comes up:

❯ clink installscripts "E:\Scoop Stuff\apps\clink-completions\0.4.1"
Stuff\apps\clink-completions\0.4.1""=="--autorun" was unexpected at this time.
❯ where clink
E:\Scoop Stuff\shims\clink.cmd

Same error pops up on the uninstallscripts command. However,

It does not show an error when ran through Command Prompt:

❯ clink installscripts "E:\Scoop Stuff\apps\clink-completions\0.4.1"
Script path 'E:\Scoop Stuff\apps\clink-completions\0.4.1' installed.
❯ where clink
E:\Scoop Stuff\shims\clink.cmd

The only place where I can think "autorun" is coming from could be here:

❯ clink autorun show
Current AutoRun values

  Current user:

    native : "E:\Scoop Stuff\apps\clink\current\clink.bat" inject --autorun --quiet
     wow64 : <unset>

  All users:

    native : <unset>
     wow64 : <unset>

I'm not aware if anything changed in the installscripts command upstream. How can I fix this?

@chrisant996
Copy link
Owner

What are the contents of the E:\Scoop Stuff\shims\clink.cmd file? It intentionally intercepts every invocation of clink, so the shim has the ability to mess things up if it has a bug.

Has your scoop directory always had a space in it, or was that a more recent change? The error message looks like something is mishandling quoted arguments.

Maybe there's a bug in the shim, or maybe there's a bug in the PowerShell version of scoop.

Whatever is happening seems to be unrelated to Clink.
You'll have to do some investigation.



image

image

@chrisant996 chrisant996 added the external The issue is due to external causes outside of Clink label Feb 5, 2023
@chrisant996
Copy link
Owner

Interesting; maybe relevant: ScoopInstaller/Scoop#5313

@rashil2000
Copy link
Contributor Author

rashil2000 commented Feb 5, 2023

The contents of clink.cmd are as follows:

@rem E:\Scoop Stuff\apps\clink\current\clink.bat
@"E:\Scoop Stuff\apps\clink\current\clink.bat"  %*

Scoop automatically creates shims based on the file extension. The code for .cmd|.bat files lives here: https://github.com/ScoopInstaller/Scoop/blob/master/lib/core.ps1#L723-L736

The same .cmd file is invoked in both PowerShell and Command Prompt, so where could the difference be?


Interesting; maybe relevant: ScoopInstaller/Scoop#5313

This one seems unrelated (it was fixed in a PR: ScoopInstaller/Scoop#5326)

@chrisant996
Copy link
Owner

@rashil2000 I took a closer look.

It used to work perfectly fine, but now when using this command in PowerShell, this error comes up:

I eventually tracked down what's happening (see further below).

I chose to make guesses/assumptions to try to fill in the blanks in the info that was provided, but I guessed wrong, which is why I couldn't reproduce the problem at first.

It does not show an error when ran through Command Prompt:

❯ clink installscripts "E:\Scoop Stuff\apps\clink-completions\0.4.1"
Script path 'E:\Scoop Stuff\apps\clink-completions\0.4.1' installed.
❯ where clink
E:\Scoop Stuff\shims\clink.cmd

I thought you meant it was a generic Command Prompt; but you must have meant CMD with Clink already injected.

Remember that Clink sets a doskey alias for clink inside a Clink session. The clink there is not invoking clink.bat, it is invoking E:\Scoop Stuff\apps\clink\current\clink_x64.exe and the clink.bat is not executed at all.

When troubleshooting, it can be useful to try variations, and especially to try the most basic variation (in this case, plain CMD.exe without Clink).

❯ clink installscripts "E:\Scoop Stuff\apps\clink-completions\0.4.1"
Stuff\apps\clink-completions\0.4.1""=="--autorun" was unexpected at this time.
❯ where clink
E:\Scoop Stuff\shims\clink.cmd

When fixing #361, I added code to clink.bat that inspects more arguments, more often.

I copied how Martin had been doing argument checks. But I wasn't paying close enough attention; the arguments checks were written in a way that produces errors when arguments are quoted and contain spaces or punctuation. clink.bat had assumed no one would pass the first argument quoted; and indeed it would be unnecessary to do so -- but e.g. clink.bat "abc def" breaks in a similar way.

Copying that syntax caused the fix for issue 361 to break with a quoted argument.

Commit 7e5f5ab fixes all of the argument parsing checks in clink.bat to work properly with quoted arguments.

@rashil2000
Copy link
Contributor Author

Remember that Clink sets a doskey alias for clink inside a Clink session. The clink there is not invoking clink.bat, it is invoking E:\Scoop Stuff\apps\clink\current\clink_x64.exe and the clink.bat is not executed at all.

Oh, right, it makes sense now.

Thank you so much for the speedy fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external The issue is due to external causes outside of Clink
Projects
None yet
Development

No branches or pull requests

2 participants