hyper
hyper copied to clipboard
Add Hyper CLI to user PATH without reboot needing
We are currently adding Hyper CLI path to user PATH in Windows registry: https://github.com/zeit/hyper/blob/262eb8ad9b7b9b15351f331765151538d67a09e2/app/utils/cli-install.js#L49-L91
A caveat is that environment variables are cached and users should open and validate "Edit environment variables for your account" dialog to force a cache refresh (or simply reboot their workstation).

@Stanzilla gave a link that could help to improve this: https://stackoverflow.com/a/11955920
process.env.Path = process.env.Path + ';' + binPath ?
Would make it work the first time Hyper launches, granted, not outside of it, but is that that important?
I think that's the better workaround @Stanzilla 👍
I have just installed and used hyper for the first time.
I open the env variables dialog box. No variable added there (no reboot yet)
I added one my-self (tried both to %USERPROFILE%\AppData\Local\hyper and with \app-
Anything I am missing, or its a know issue?
@buffos Hyper CLI is only available on our canary release (upcoming v2) You don't have to add anything by yourself :)
FYI I created a more generic version of this issue back in 2016 😄 https://github.com/zeit/hyper/issues/1211, maybe you can close it (https://github.com/zeit/hyper/issues/2284#issuecomment-359806862)?
@Stanzilla I think this is important to have hyper in PATH (outside itself). I think that hyper --verbose will be used to make some diagnostics for example.
@chabou my idea was mainly meant as a workaround, since we can't easily refresh the environment at Hyper launch BUT we can add it to process.env temporarily. That change gets lost as soon as Hyper closes. We would not drop setting the registry change for it, though.
That means we have the following scenario:
Current:
User installs Hyper
Hyper gets added to PATH
Hyper opens, cannot refresh the env so hyper cli does not work
User opens different terminal emulator
hyper cli also does not work if said terminal emulator did not refresh env.
After the change:
User installs Hyper
Hyper gets added to PATH
Hyper opens, temporarily adds hyper to process.env so hyper cli works
User opens different terminal emulator
hyper cli also does not work if said terminal emulator did not refresh env.
I don't really see a downside to it?
For Windows, what about using the refreshenv.cmd that chocolately includes? I ran it upon first opening of hyper and it worked excellently. So the install could run it or hyper could run on first open? (have not dug into the app so I'm not familiar with how exactly it would be best implemented).
https://github.com/chocolatey/choco/blob/master/src/chocolatey.resources/redirects/RefreshEnv.cmd
@echo off
::
:: RefreshEnv.cmd
::
:: Batch file to read environment variables from registry and
:: set session variables to these values.
::
:: With this batch file, there should be no need to reload command
:: environment every time you want environment changes to propagate
echo | set /p dummy="Reading environment variables from registry. Please wait... "
goto main
:: Set one environment variable from registry key
:SetFromReg
"%WinDir%\System32\Reg" QUERY "%~1" /v "%~2" > "%TEMP%\_envset.tmp" 2>NUL
for /f "usebackq skip=2 tokens=2,*" %%A IN ("%TEMP%\_envset.tmp") do (
echo/set %~3=%%B
)
goto :EOF
:: Get a list of environment variables from registry
:GetRegEnv
"%WinDir%\System32\Reg" QUERY "%~1" > "%TEMP%\_envget.tmp"
for /f "usebackq skip=2" %%A IN ("%TEMP%\_envget.tmp") do (
if /I not "%%~A"=="Path" (
call :SetFromReg "%~1" "%%~A" "%%~A"
)
)
goto :EOF
:main
echo/@echo off >"%TEMP%\_env.cmd"
:: Slowly generating final file
call :GetRegEnv "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" >> "%TEMP%\_env.cmd"
call :GetRegEnv "HKCU\Environment">>"%TEMP%\_env.cmd" >> "%TEMP%\_env.cmd"
:: Special handling for PATH - mix both User and System
call :SetFromReg "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" Path Path_HKLM >> "%TEMP%\_env.cmd"
call :SetFromReg "HKCU\Environment" Path Path_HKCU >> "%TEMP%\_env.cmd"
:: Caution: do not insert space-chars before >> redirection sign
echo/set Path=%%Path_HKLM%%;%%Path_HKCU%% >> "%TEMP%\_env.cmd"
:: Cleanup
del /f /q "%TEMP%\_envset.tmp" 2>nul
del /f /q "%TEMP%\_envget.tmp" 2>nul
:: Set these variables
call "%TEMP%\_env.cmd"
echo | set /p dummy="Done"
echo .
Hey just wanted to check if this was in 3 or if I needed to do a manual refresh of my env variables in Windows?
Is this issue still open? I am first time contributer.
The RefreshEnv.cmd workaround works but only in the current tab.
c:\dev>hyper i hyper-material-theme
'hyper' is not recognized as an internal or external command,
operable program or batch file.
c:\dev>RefreshEnv.cmd
Refreshing environment variables from registry for cmd.exe. Please wait...Finished..
c:\dev>hyper i hyper-material-theme
hyper-material-theme installed successfully!
2023
This article may be useful: https://web.archive.org/web/20091124062536/http://support.microsoft.com/kb/104011
Hello Hyper, this is simple. Had to resolve this in my company's proprietary CLI and that is a way smaller audience ...
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")