DEV Community

Cover image for Faking the tmux experience on Windows using AutoHotkey
kanndide
kanndide

Posted on

Faking the tmux experience on Windows using AutoHotkey

I watch too many bad-ass developers on YouTube moving around their terminal's and text editors in ways that only bad-asses can. However, I would need to migrate from Windows in order to achieve this sort of skill. Windows just doesn't have the same amount of tools focused on making the life of the developer easier like Linux does.

So, I decided to see if there was any type of functionality I could mimic on Windows without having to install and run the Windows Subsystem for Linux. There has always been something about have two operations systems on my machine that just makes me feel dirty. I want my daily driver to be pure Linux, I don't want to settle for the small VM that Windows gives me just to help scratch an itch.

So, I decided to see what I could do with the tools available to Windows that don't require me to hack together something or spend too much time coding. First up, the terminal.

I chose Alacritty for this. Why? Because it's written in Rust. Is there any other reason? It also has a pretty simple and has an easy to understand settings page and uses TOML. It also has built in support for vi motions. All wins. It's pretty easy to install as well, just follow the link above. I went with the portable version. Just make sure you note where it is going to look for the configuration files.

My settings are very simple and look like this:

import = ["C:/Users/yourusername/AppData/Roaming/alacritty/nightowl/night_owl.toml"]

[shell]
program = "pwsh"
args = []

# Font configuration
[font]
normal.family = "Dank Mono"
size = 18

# Window settings
[window]
opacity = 0.85
padding.x = 5
padding.y = 15
startup_mode = "Maximized"
decorations = "Full"

# Scrolling settings
[scrolling]
history = 10000
multiplier = 3

[keyboard]
bindings = [
  { key = "M", mods = "Control | Shift", action = "Minimize" }
]
Enter fullscreen mode Exit fullscreen mode

Pretty simple, right? The only key-binding I have is so I can use it to minimize my terminal windows when I start hacking together a solution to running multiple terminals at once. To do this, I use AutoHotkey.

Pseuod-tmux:

; AutoHotkey v2 Script to Open Alacritty as "Terminal 1" with Ctrl+Shift+1

#Requires AutoHotkey v2.0+

; Hotkey for Ctrl + Shift + 1 (Terminal 1)
^+1:: {
    title := "Terminal 1"

    if WinExist(title) 
        WinActivate 
    else 
        Run('alacritty.exe -t "' title '"')
}

; Hotkey for Ctrl + Shift + 2 (Terminal 2)
^+2:: {
    title := "Terminal 2"

    ; Check if a window with the title "Terminal 1" already exists
    if WinExist(title) 
        WinActivate 
    else 
        Run('alacritty.exe -t "' title '"')
}

; Hotkey for Ctrl + Shift + 3 (Terminal 3)
^+3:: {
    title := "Terminal 3"
    if WinExist(title)
        WinActivate(title)
    else
        Run('alacritty.exe -t "' title '"')
}

; Hotkey for Ctrl + Shift + 4 (Terminal 4)
^+4:: {
    title := "Terminal 4"
    if WinExist(title)
        WinActivate(title)
    else
        Run('alacritty.exe -t "' title '"')
}

; Hotkey for Ctrl + Shift + 5 (Terminal 5)
^+5:: {
    title := "Terminal 5"
    if WinExist(title)
        WinActivate(title)
    else
        Run('alacritty.exe -t "' title '"')
}

; Hotkey for Ctrl + Shift + 6 (Terminal 6)
^+6:: {
    title := "Terminal 6"
    if WinExist(title)
        WinActivate(title)
    else
        Run('alacritty.exe -t "' title '"')
}

; Hotkey for Ctrl + Shift + 7 (Terminal 7)
^+7:: {
    title := "Terminal 7"
    if WinExist(title)
        WinActivate(title)
    else
        Run('alacritty.exe -t "' title '"')
}

; Hotkey for Ctrl + Shift + 8 (Terminal 8)
^+8:: {
    title := "Terminal 8"
    if WinExist(title)
        WinActivate(title)
    else
        Run('alacritty.exe -t "' title '"')
}

; Hotkey for Ctrl + Shift + 9 (Terminal 9)
^+9:: {
    title := "Terminal 9"
    if WinExist(title)
        WinActivate(title)
    else
        Run('alacritty.exe -t "' title '"')
}

; Hotkey for Ctrl + Shift + 0 (Terminal 10)
^+0:: {
    title := "Terminal 10"
    if WinExist(title)
        WinActivate(title)
    else
        Run('alacritty.exe -t "' title '"')
}

Enter fullscreen mode Exit fullscreen mode

Is that not the stupidest shit?

Essentially, this just opens an instance of Alacritty with a unique name, which allows me to cycle between them suing key bindings (ctrl-shift-number) in this case.

The best way to do this would be to actually learn how to manage virtual desktops in Windows with AutoHotkey, but I don't even know if that's possible. For now, I accept a hacky workaround with hotkeys.

At least I'm not using Windows Terminal.

Happy Coding!

Top comments (1)

Collapse
 
kanndide profile image
kanndide

It's much easier to just add another keybinding in Alacritty to create a new window (and not a whole new instance) and then just minimize and close as necessary. If I removed any transparency on the terminal, minimizing would be a none issue... but I refuse.