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

rakubrew init on Windows tells me to run rakubrew init for PowerShell instructions #81

Closed
ugexe opened this issue Jan 19, 2025 · 5 comments

Comments

@ugexe
Copy link
Contributor

ugexe commented Jan 19, 2025

The instructions from rakubrew init tells me to run rakubrew init for powershell instructions. Yet I'm already running that command from powershell.

(Note that the above does not enable auto-loading in PowerShell, that needs a
separate installation procedure. Call C:\rakubrew\bin\rakubrew.exe init in a PowerShell window
for respective installation instructions.)

PS C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools> C:\rakubrew\bin\rakubrew.exe init
To load rakubrew in CMD automatically you have to do two things:

1. Check that you don't already have a CMD autorun script set.

    reg query "HKCU\Software\Microsoft\Command Processor" /v AutoRun

  If you don't have an autorun script set (the above command returns an error) you can set one using:

    reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /t REG_EXPAND_SZ /d \""%"USERPROFILE"%\Documents\CMD_profile.cmd"\" /f

2. Add the following code to the end of the autorun script you linked in step 1:

    @echo off
    setlocal EnableDelayedExpansion
    set "cmd=!cmdcmdline!"
    if "!cmd!" == "!cmd:/=!" (
        endlocal
        FOR /f "delims=" %%i in ('"C:\rakubrew\bin\rakubrew.exe" init Cmd') do @%%i
    )

  You can easily do that from a CMD prompt using the following command:

    (
    echo @echo off
    echo setlocal EnableDelayedExpansion
    echo set "cmd=!cmdcmdline!"
    echo if "!cmd!" == "!cmd:/=!" ^(
    echo     endlocal
    echo     FOR /f "delims=" %%i in ^('"C:\rakubrew\bin\rakubrew.exe" init Cmd'^) do @%%i
    echo ^)
    ) >> "%USERPROFILE%\Documents\CMD_profile.cmd"

  If you use a different autorun script location, replace the path in the command above.

(Note that the above does *not* enable auto-loading in PowerShell, that needs a
separate installation procedure. Call `C:\rakubrew\bin\rakubrew.exe init` in a PowerShell window
for respective installation instructions.)
@patrickbkr
Copy link
Member

The logic to detect whether it's PS or CMD is here. It relies on some env var trickery. (See those 6 lines of code and the linked StackOverflow explanation.) Can you check how the environment looks on your machine? Maybe you can identify some other clue that gives away whether we're in a PS or CMD?

@ugexe
Copy link
Contributor Author

ugexe commented Jan 20, 2025

PS C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools> echo $env:PSMODULEPATH
C:\Program Files\WindowsPowerShell\Modules;C:\Mac\Home\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

PS C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools> echo $env:USERPROFILE
C:\Users\nlogan

I don't see anything else in my environment variables that could be used to signal the shell being used either. I'm kind of thinking there is not a good way to tell which shell a user is using. Giving instructions for both powershell and cmd could be a less than ideal solution.

@patrickbkr
Copy link
Member

Looking at your output, I think the C:\Mac\Home\Documents\WindowsPowerShell\Modules thing is the path we are looking for. It's not at the begining and it's some other home, but it's a home.

Given that usage slowly shifts from CMD to PS, we could err on the side of PS and simply check, whether $env:PSMODULEPATH contains \Documents\WindowsPowerShell\Modules;.

Can you validate whether that would work on your setup (i.e. what does that variable look in a CMD)?

@ugexe
Copy link
Contributor Author

ugexe commented Jan 20, 2025

Looking at your output, I think the C:\Mac\Home\Documents\WindowsPowerShell\Modules thing is the path we are looking for. It's not at the begining and it's some other home, but it's a home.

To me that seems like an artifact of Parallels and however it was configured to share disk access. In other words I suspect it would be possible for that path to not exist in my environment regardless of powershell, although it is true that the path does not show up in PSModulePath on cmd. Then again maybe it would always exist in some form, just not as a path to the documents folder on my mac.

# cmd.exe

C:\Users\nlogan>set
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\nlogan\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(Arm)=C:\Program Files (Arm)\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=NICKLOGAN344B
ComSpec=C:\WINDOWS\system32\cmd.exe
DriverData=C:\Windows\System32\Drivers\DriverData
EFC_4160=1
HOMEDRIVE=C:
HOMEPATH=\Users\nlogan
LOCALAPPDATA=C:\Users\nlogan\AppData\Local
LOGONSERVER=\\NICKLOGAN344B
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
Path=C:\rakubrew\bin\;C:\Perl\bin;C:\Program Files\Parallels\Parallels Tools\Applications;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Users\nlogan\AppData\Local\Microsoft\WindowsApps
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=ARM64
PROCESSOR_IDENTIFIER=ARMv8 (64-bit) Family 8 Model 0 Revision   0,
PROCESSOR_LEVEL=0
PROCESSOR_REVISION=0000
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(Arm)=C:\Program Files (Arm)
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\Users\nlogan\AppData\Local\Temp
TMP=C:\Users\nlogan\AppData\Local\Temp
USERDOMAIN=NICKLOGAN344B
USERDOMAIN_ROAMINGPROFILE=NICKLOGAN344B
USERNAME=nlogan
USERPROFILE=C:\Users\nlogan
windir=C:\WINDOWS
# powershell

PS C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools> echo $env:PSModulePath
C:\Program Files\WindowsPowerShell\Modules;C:\Mac\Home\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

PS C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools> Get-ChildItem Env:

Name                           Value
----                           -----
__DOTNET_ADD_32BIT             1
__DOTNET_PREFERRED_BITNESS     32
__VSCMD_PREINIT_PATH           C:\rakubrew\bin\;C:\Perl\bin;C:\Program Files\Parallels\Parallels Tools\Ap...
ALLUSERSPROFILE                C:\ProgramData
APPDATA                        C:\Users\nlogan\AppData\Roaming
CommandPromptType              Native
CommonProgramFiles             C:\Program Files (x86)\Common Files
CommonProgramFiles(Arm)        C:\Program Files (Arm)\Common Files
CommonProgramFiles(x86)        C:\Program Files (x86)\Common Files
CommonProgramW6432             C:\Program Files\Common Files
COMPUTERNAME                   NICKLOGAN344B
ComSpec                        C:\WINDOWS\system32\cmd.exe
DevEnvDir                      C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\
DriverData                     C:\Windows\System32\Drivers\DriverData
EFC_4160                       1
ExtensionSdkDir                C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs
EXTERNAL_INCLUDE               C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MS...
Framework40Version             v4.0
FrameworkDir                   C:\Windows\Microsoft.NET\Framework\
FrameworkDir32                 C:\Windows\Microsoft.NET\Framework\
FrameworkVersion               v4.0.30319
FrameworkVersion32             v4.0.30319
HOMEDRIVE                      C:
HOMEPATH                       \Users\nlogan
INCLUDE                        C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MS...
LIB                            C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MS...
LIBPATH                        C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MS...
LOCALAPPDATA                   C:\Users\nlogan\AppData\Local
LOGONSERVER                    \\NICKLOGAN344B
NUMBER_OF_PROCESSORS           4
OS                             Windows_NT
Path                           C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MS...
PATHEXT                        .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL
PROCESSOR_ARCHITECTURE         x86
PROCESSOR_ARCHITEW6432         ARM64
PROCESSOR_IDENTIFIER           ARMv8 (64-bit) Family 8 Model 0 Revision   0,
PROCESSOR_LEVEL                0
PROCESSOR_REVISION             0000
ProgramData                    C:\ProgramData
ProgramFiles                   C:\Program Files (x86)
ProgramFiles(Arm)              C:\Program Files (Arm)
ProgramFiles(x86)              C:\Program Files (x86)
ProgramW6432                   C:\Program Files
PROMPT                         $P$G
PSModulePath                   C:\Program Files\WindowsPowerShell\Modules;C:\Mac\Home\Documents\WindowsPo...
PUBLIC                         C:\Users\Public
SESSIONNAME                    Console
SystemDrive                    C:
SystemRoot                     C:\WINDOWS
TEMP                           C:\Users\nlogan\AppData\Local\Temp
TMP                            C:\Users\nlogan\AppData\Local\Temp
UCRTVersion                    10.0.22621.0
UniversalCRTSdkDir             C:\Program Files (x86)\Windows Kits\10\
USERDOMAIN                     NICKLOGAN344B
USERDOMAIN_ROAMINGPROFILE      NICKLOGAN344B
USERNAME                       nlogan
USERPROFILE                    C:\Users\nlogan
VCIDEInstallDir                C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\IDE...
VCINSTALLDIR                   C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\
VCToolsInstallDir              C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MS...
VCToolsRedistDir               C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Redist\M...
VCToolsVersion                 14.42.34433
VisualStudioVersion            17.0
VS170COMNTOOLS                 C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\
VSCMD_ARG_app_plat             Desktop
VSCMD_ARG_HOST_ARCH            x86
VSCMD_ARG_TGT_ARCH             x86
VSCMD_VER                      17.12.3
VSINSTALLDIR                   C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\
windir                         C:\WINDOWS
WindowsLibPath                 C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.22621.0;C:\Progr...
WindowsSdkBinPath              C:\Program Files (x86)\Windows Kits\10\bin\
WindowsSdkDir                  C:\Program Files (x86)\Windows Kits\10\
WindowsSDKLibVersion           10.0.22621.0\
WindowsSdkVerBinPath           C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\
WindowsSDKVersion              10.0.22621.0\

@patrickbkr
Copy link
Member

I hope I have it sufficiently fixed in v42. I implemented both, shell detection now leans more on the PowerShell side and the init text now shows which shell was detected and how to get info for other shells should the detection have been wrong.

@ugexe ugexe closed this as completed Jan 25, 2025
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

2 participants