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

Add Hyper CLI to user PATH without reboot needing #2823

Open
chabou opened this issue Apr 15, 2018 · 14 comments
Open

Add Hyper CLI to user PATH without reboot needing #2823

chabou opened this issue Apr 15, 2018 · 14 comments
Assignees
Labels
⌨️ CLI tool Issue or PR related to CLI tool good first issue Issue is good for Hyper newcomers help wanted Contributions wanted towards the issue 🖼 Platform: Windows Issue pertains to Windows
Milestone

Comments

@chabou
Copy link
Collaborator

chabou commented Apr 15, 2018

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 chabou added help wanted Contributions wanted towards the issue good first issue Issue is good for Hyper newcomers 🖼 Platform: Windows Issue pertains to Windows labels Apr 15, 2018
@chabou chabou added this to the 2.1.0 milestone Apr 15, 2018
@Stanzilla
Copy link
Collaborator

Stanzilla commented Apr 15, 2018

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?

@albinekb
Copy link
Contributor

I think that's the better workaround @Stanzilla 👍

@buffos
Copy link

buffos commented Apr 16, 2018

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?

@chabou
Copy link
Collaborator Author

chabou commented Apr 16, 2018

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

@Tyriar
Copy link
Contributor

Tyriar commented Apr 18, 2018

FYI I created a more generic version of this issue back in 2016 😄 #1211, maybe you can close it (#2284 (comment))?

@chabou
Copy link
Collaborator Author

chabou commented Apr 20, 2018

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

@Stanzilla
Copy link
Collaborator

Stanzilla commented Apr 20, 2018

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

@LonghornRach
Copy link

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 .

@jcklpe
Copy link

jcklpe commented Feb 27, 2019

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?

@Stanzilla Stanzilla added the ⌨️ CLI tool Issue or PR related to CLI tool label Oct 10, 2019
@sandeephalder
Copy link

sandeephalder commented Aug 18, 2020

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

@catamphetamine
Copy link

catamphetamine commented Apr 28, 2021

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!

@adilaxmdv
Copy link

2023

@anubhav1206
Copy link

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

@JustinKirkJohnson
Copy link

JustinKirkJohnson commented May 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⌨️ CLI tool Issue or PR related to CLI tool good first issue Issue is good for Hyper newcomers help wanted Contributions wanted towards the issue 🖼 Platform: Windows Issue pertains to Windows
Projects
None yet
Development

No branches or pull requests

13 participants