hyper icon indicating copy to clipboard operation
hyper copied to clipboard

Add Hyper CLI to user PATH without reboot needing

Open chabou opened this issue 7 years ago • 14 comments

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

chabou avatar Apr 15 '18 19:04 chabou

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?

Stanzilla avatar Apr 15 '18 21:04 Stanzilla

I think that's the better workaround @Stanzilla 👍

albinekb avatar Apr 16 '18 08:04 albinekb

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-) It now "sees" the hyper command, but if I run hyper i it will just open a new terminal (nothing installed ( i can install plugins by adding in the hyper.js file)

Anything I am missing, or its a know issue?

buffos avatar Apr 16 '18 08:04 buffos

@buffos Hyper CLI is only available on our canary release (upcoming v2) You don't have to add anything by yourself :)

chabou avatar Apr 16 '18 10:04 chabou

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)?

Tyriar avatar Apr 18 '18 17:04 Tyriar

@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 avatar Apr 20 '18 15:04 chabou

@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?

Stanzilla avatar Apr 20 '18 15:04 Stanzilla

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 .

LonghornRach avatar Aug 29 '18 02:08 LonghornRach

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?

jcklpe avatar Feb 27 '19 04:02 jcklpe

Is this issue still open? I am first time contributer.

sandeephalder avatar Aug 18 '20 03:08 sandeephalder

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!

catamphetamine avatar Apr 28 '21 11:04 catamphetamine

2023

adilaxmdv avatar Mar 11 '23 08:03 adilaxmdv

This article may be useful: https://web.archive.org/web/20091124062536/http://support.microsoft.com/kb/104011

anubhav1206 avatar Mar 31 '23 14:03 anubhav1206

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")

JustinKirkJohnson avatar May 09 '24 21:05 JustinKirkJohnson