Skip to content

Instantly share code, notes, and snippets.

@legowerewolf
Last active December 29, 2023 16:45
Show Gist options
  • Save legowerewolf/a3e0eb7830752488fec329c7bdcb2d2a to your computer and use it in GitHub Desktop.
Save legowerewolf/a3e0eb7830752488fec329c7bdcb2d2a to your computer and use it in GitHub Desktop.
Selecting a shell on startup in the Hyper terminal emulator
@ECHO off
:top
CLS
ECHO Choose a shell:
ECHO [1] cmd
ECHO [2] bash
ECHO [3] PowerShell
ECHO [4] Python
ECHO.
ECHO [5] restart elevated
ECHO [6] exit
ECHO.
CHOICE /N /C:123456 /M "> "
CLS
IF ERRORLEVEL ==6 GOTO end
IF ERRORLEVEL ==5 powershell -Command "Start-Process hyper -Verb RunAs"
IF ERRORLEVEL ==4 python
IF ERRORLEVEL ==3 powershell
IF ERRORLEVEL ==2 bash
IF ERRORLEVEL ==1 cmd
CLS
ECHO Switch or exit?
ECHO [1] Switch
ECHO [2] Exit
CHOICE /N /C:12 /D 2 /T 5 /M "> "
IF ERRORLEVEL ==2 GOTO end
IF ERRORLEVEL ==1 GOTO top
:end
$knownshells = @(
@{
Name = "CMD"
Executable = "$env:SystemRoot\System32\cmd.exe"
},
@{
Name = "Powershell 5.1"
Executable = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"
},
@{
Name = "Powershell 6 (Core)"
Executable = "$env:ProgramFiles\PowerShell\6\pwsh.exe"
},
@{
Name = "Powershell 7 (Core)"
Executable = "$env:ProgramFiles\PowerShell\7\pwsh.exe"
},
@{
Name = "Bash on Ubuntu"
Executable = "$env:ProgramFiles\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_1804.2020.5.0_x64__79rhkp1fndgsc\ubuntu.exe"
},
@{
Name = "Git Bash"
Executable = "$env:ProgramFiles\Git\git-bash.exe"
}
) | Where-Object { Test-Path -Path $_.Executable }
"Choose a shell:"
$index = 1; $teststring = ""
foreach ($shell in $knownshells) {
"[$index] $($shell.Name)"
$teststring += $index++
}
""
do { $keyPress = [System.Console]::ReadKey() } until ($teststring.Contains($keyPress.Key));
$choice = $knownshells[($keyPress.KeyChar.ToString() -as [int]) - 1]
Start-Process -Path $choice.Executable -NoNewWindow -Wait -ArgumentList $choice.ArgumentList
exit

Hyperstart

I'm not supporting this anymore - I use Windows Terminal now.

Short script for Windows that allows you to select which shell you want when Hyper starts. As flexible as the windows command line.

Install

  1. Grab the script from below.
  2. Save it wherever you want.
  3. Set your shell to '' (meaning CMD on Windows) and your shellArgs to ["/C", "path\\to\\your\\hyperstart.bat"]
  4. Additional steps
  • To enable the "launch elevated" line, Hyper needs to be on the PATH.

Customize

Add a shell

  1. Add another ECHO line with a new number: ECHO [4] Python
  2. Add the corresponding number to the CHOICE line: CHOICE /N /C:1234
  3. Add the corresponding IF ERRORLEVEL line below the CLS line: IF ERRORLEVEL ==4 python
  4. Fix up the other numbers, if necessary.
@genio
Copy link

genio commented May 9, 2018

This doesn't seem to work in hyper v2.0


[Window Title]
Error

[Main Instruction]
A JavaScript error occurred in the main process

[Content]
Uncaught Exception:
TypeError: Cannot read property 'resize' of undefined
    at Server.Window.rpc.on (C:\Users\genio\AppData\Local\hyper\app-2.0.0\resources\app.asar\ui\window.js:146:14)
    at emitOne (events.js:115:13)
    at Server.emit (events.js:210:7)
    at Server.ipcListener (C:\Users\genio\AppData\Local\hyper\app-2.0.0\resources\app.asar\rpc.js:33:11)
    at emitTwo (events.js:125:13)
    at EventEmitter.emit (events.js:213:7)
    at WebContents.<anonymous> (C:\Users\genio\AppData\Local\hyper\app-2.0.0\resources\electron.asar\browser\api\web-contents.js:266:13)
    at emitTwo (events.js:125:13)
    at WebContents.emit (events.js:213:7)

[OK]

@szul
Copy link

szul commented May 14, 2018

Getting the same error now as @genio.

@wordyallen
Copy link

same error

@mckernanin
Copy link

mckernanin commented Jun 15, 2018

I had the same issue, the first part confused me. /C represents a flag passed to cmd.exe, not your C drive. I put hyperstart.bat in my user folder, and the following setting works great for me:

    shell: '',
    shellArgs: ["/C","C:\\Users\\Kevin McKernan\\hyperstart.bat"],

@ammein
Copy link

ammein commented Jul 11, 2018

Bash Error

I got this error when opening bash :

'bash' is not recognized as an internal or external command,
operable program or batch file.
Microsoft Windows [Version 10.0.17134.165]
(c) 2018 Microsoft Corporation. All rights reserved

Solution Found :

Make sure you add your bash to PATH :

  1. Press Windows Key (Windows 10) and start typing edit environment variables
  2. Then you go to User Variable section and find text named path.
  3. Click on it and press edit.
  4. If you don't have this path C:\Program Files\Git\bin . Click New and Browse to that path.
  5. Save and Exit. You're done !

@JosiahSlade
Copy link

@legowerewolf can you clarify how you PATH looks like for elevated line to work. I have hyper in my user var PATH but not sure if Im missing something since I'm getting the resize errors as well

@JosiahSlade
Copy link

If you're having the resize error mentioned above, make sure the file hyperstart.bat is a windows batch file and not a text document. You may have it as a text if you saved it directly from the page. It worked for me once it's a batch file.

@brunomedeiros0121
Copy link

Nice job!

@sntnupl
Copy link

sntnupl commented Apr 5, 2019

Awesome Job!
I had the same issue as seen by @ammein above.
I did not want to add the ms-git's version of bash in my PATH, as I would soon setup WSL, and I want that application's bash to be in PATH.

So, if like me, you have multiple bashes :-), you can do the following:

@ECHO off
:top
CLS
ECHO Choose a shell:
ECHO [1] cmd
ECHO [2] bash
ECHO [3] PowerShell
ECHO [4] Python
ECHO.
ECHO [5] restart elevated
ECHO [6] exit
ECHO.

CHOICE /N /C:123456 /M "> "
CLS
IF ERRORLEVEL ==6 GOTO end
IF ERRORLEVEL ==5 powershell -Command "Start-Process hyper -Verb RunAs"
IF ERRORLEVEL ==4 python
IF ERRORLEVEL ==3 powershell
IF ERRORLEVEL ==2 "C:\Program Files\Git\bin\bash.exe"
IF ERRORLEVEL ==1 cmd

CLS
ECHO Switch or exit?
ECHO [1] Switch
ECHO [2] Exit

CHOICE /N /C:12 /D 2 /T 5 /M "> "
IF ERRORLEVEL ==2 GOTO end
IF ERRORLEVEL ==1 GOTO top

:end

In other words, you can give full path to the bash.exe you want to execute.
Once I install WSL, I will extend this script, to include 2 bash options, each pointing to their respective exes.

@peter-avila
Copy link

peter-avila commented May 6, 2019

Batch file no longer runs (resolved)
After a recent update (I'm now on 3.0.0 stable), my version of this batch files no longer runs from shellArgs, or any other configs when starting Hyper. It looks like the .hyper.js config file is now located in the Windows roaming AppData folder for Hyper (%USERPROFILE%\AppData\Roaming\Hyper). Once I moved my config and batch file there, it works as expected.

@legowerewolf
Copy link
Author

I'm just amazed that this one dinky little script that I put together in half an hour or so has gotten more response than any of my other projects that I've put considerably more time into.
Y'all make me smile.

@lopugit
Copy link

lopugit commented Apr 23, 2021

I'm just amazed that this one dinky little script that I put together in half an hour or so has gotten more response than any of my other projects that I've put considerably more time into.
Y'all make me smile.

I say thank you.

I am having a problem where I can't close any tabs or panes though, and even closing the whole window ends up with a crash. Opening new tabs and selecting the shell works fine. Have you encountered anyone with this issue too?

May I ask what the .ps1 file is for? There's no mention of what it is intended for? I have just been using the .bat file for now.

@legowerewolf
Copy link
Author

@lopugit - the ps1 file is a PowerShell script file that's essentially equivalent to the .bat file. As for the other problem? I have no clue. I actually haven't used Hyper in ages - I've been using Windows Terminal.

@lopugit
Copy link

lopugit commented Apr 24, 2021

@lopugit - the ps1 file is a PowerShell script file that's essentially equivalent to the .bat file. As for the other problem? I have no clue. I actually haven't used Hyper in ages - I've been using Windows Terminal.

I've just looked into windows terminal, but it seems they're having issues implementing traditional basic window transparency like hyper has.

May I ask how you implement the ps1 script? I couldn't just substitute it in place of the .bat file as the runtime argument

@legowerewolf
Copy link
Author

@lopugit

I've just looked into windows terminal, but it seems they're having issues implementing traditional basic window transparency like hyper has.

Fair enough. You don't like the acrylic, then?

May I ask how you implement the ps1 script? I couldn't just substitute it in place of the .bat file as the runtime argument

Set shell to whatever PowerShell executable you want to use, either powershell for 5.x or pwsh for 6.x+. Set shellArgs to ["path\\to\\hyperstart.ps1"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment