36

Is there an alternative to tmux/screen that would work on Windows with Powershell? I'm aware of Powerscreen, but it seems dead for a long time. Cygwin wouldn't work with Powershell, would it? Console2 is very poors man solution.

Any other thought?

9

It's not precisely analogous to tmux or screen, but PowerShell has a facility for managing remote sessions. Ed Wilson wrote a blog post about it entitled Learn How to Manage Remote PowerShell Sessions, which might help. Also see the about_PSSessions PowerShell help topic.

Can you say more about what you're trying to accomplish?

7

Try Cmder. It's awesome! It even bundled with git for windows. http://cmder.net/

1
  • 2
    That appears to be just a terminal emulator, which is cool but that isn't what screen/tmux do. They provide persistent sessions which you can reconnect to if you get disconnected etc so the tmux session is on the server side.
    – Benj
    Dec 17 '19 at 14:27
3

You don't specify your requirements, so it's somewhat hard to answer your post.

You could try the free Console, which can incorporate PowerShell tabs :

Console is a Windows console window enhancement. Console features include: multiple tabs, text editor-like text selection, different background types, alpha and color-key transparency, configurable font, different window styles.

For details see this article : Console – Windows Command Prompt alternative for Windows and PowerShell.

image

(Note: Remember that this answer is from 2012.)

3

it's been a while since I've used Windows but just came across https://wezfurlong.org/wezterm/features.html which would fit my requirements quite well

among other things it has tabs and vertical/horizontal splits

1
  • 1
    In that case, the new Windows Terminal would probably have fit your needs as well. It looks to have features on par with (or ahead of, in some cases) Wez's. Also ConEmu/Cmder, as @aztack's answer. That said, with Windows Subsystem for Linux, it's really possible to use tmux directly with PowerShell. I'll write up a separate answer on that. I hadn't brought it back up since I figured you'd moved on from the question, but since you bumped it today, I'll go ahead and add it. Apr 18 at 22:24
3

Although it wasn't possible when this question was originally asked, with Windows Subsystem for Linux, it's now possible to use a "real" tmux to manage PowerShell windows.

Short-version

In a WSL instance with tmux installed, set up your ~/.tmux.conf with:

set -g default-command "cd $(pwsh.exe -c 'Write-Host -NoNewLine \$env:userprofile' | xargs -0 wslpath); exec pwsh.exe --nologo"
set-window-option -g automatic-rename off
bind c new-window -n "PowerShell"

Benefits and Features

Most of the features you'd normally expect from tmux, including:

  • Full (?) hotkeys support
  • Scrollback / Copy mode for PowerShell
  • And many more

Limitations

  • If the original session is disconnected, re-attaching will result in a broken pipe. However, you can attach multiple clients at once, as long as the original remains open.

More details

There are several ways to set this up, but here's how I'm doing it at the moment:

  • Install Windows Subsystem for Linux. You don't have to enable WSL2; just WSL v1 will work fine for this (and perhaps better than WSL2).

  • Install the Alpine Linux distribution. I use this as the base for the tmux feature, since it has very low overhead (less than 12MB, including tmux).

  • The next few steps are optional. I create a new, cloned WSL instance for PowerShell tmux. You could just use the default Alpine instance, but I like to have single-purpose WSL instances, similar to Docker containers.

    mkdir $env:userprofile\Documents\WSL\instances # Or wherever you want to set this up
    mkdir $env:userprofile\Documents\WSL\images
    cd $env:userprofile\Documents\WSL
    wsl --export Alpine .\images\alpine_base.tar
    mkdir .\instances\posh_tmux
    wsl --import posh_tmux .\instances\posh_tmux .\images\alpine_base.tar --version 1 
    
  • Launch the WSL instance as root with wsl -d posh_tmux -u root

  • adduser tmux, and give it a password.

  • Set the default user for the instance by creating /etc/wsl.conf with the following contents:

    [user]
    default = tmux
    
  • apk add tmux to install tmux

  • Exit the session, relaunch with wsl ~ -d tmux (omitting the username, since it will now default to the tmux user)

  • Create a ~/.tmux.conf with the following:

    set -g default-command "cd $(pwsh.exe -c 'Write-Host -NoNewLine \$env:userprofile' | xargs -0 wslpath); exec pwsh.exe --nologo"
    set-window-option -g automatic-rename off
    bind c new-window -n "PowerShell"
    
    # Give this tmux a "PowerShell blue" color to differentiate it
    set -g status-bg blue
    
    # Use UTF8
    set -qg utf8
    set-window-option -qg utf8 on
    
    # Recommended, to avoid the Ctrl+B finger-gymnastics
    # Change default prefix to Screen's
    unbind C-b
    set-option -g prefix C-a
    bind-key C-a send-prefix
    bind-key -n C-b send-prefix
    bind C-a last-window
    
    # Optional
    # split panes using - and |
    bind | split-window -h
    bind - split-window -v
    unbind '"'
    unbind %
    
    set -g history-limit 10000
    
    set -g default-terminal "screen-256color"
    
  • Create a ~/.profile with the following:

    if tmux has-session -t=posh; then
      exec tmux attach-session -t posh
    else
      exec tmux new-session -s posh -n PowerShell
    fi
    
  • Set up a PowerShell Core tmux profile in Windows Terminal, ConEmu, or however you prefer. The launch command is simply wsl -d tmux_posh

  • If you need to access the instance without entering tmux/PowerShell (for instance, to sudo apk upgrade or to edit the config), launch instead with wsl ~ -d tmux_posh -e sh (or wsl ~ -d tmux_posh -u root).

  • You can access tmux commands from within PowerShell by wsl -d tmux_posh -e tmux <tmux_command. For instance, wsl -d tmux_posh -e tmux rename-window host1. TODO: Create a tmux wrapper PowerShell function for this.

  • TODO: PowerShell prompt function to set the window name dynamically to the last executed command

2
  • 1
    Your walkthrough is over and above. Thank you! I feel corporate advancement pulling me back toward Windows like a black hole, and I've been anxiously scanning the horizon for something like this. Sep 18 at 0:41
  • Thanks @LaTeX2enub1336. I can understand that. WSL gives us CLI-junkies some good alternatives in Windows. It's sometimes fun to see just how much we can use it and abuse it. I've come across one person here and on Reddit that has run 17 different distros (at last count) on WSL. On a similar question/answer to this one, you might also be interested in this tip for using Linux ls (or exa, or really a lot of Linux commands) in PowerShell. Sep 18 at 1:55
2

I am partial to Extraterm, it has plenty of advanced functinality
it supports Powershell, wls, cmd, cwgyn, and more.

https://extraterm.org/
https://github.com/sedwards2009/extraterm/releases

enter image description here

0

I recently ran into the issue myself. I was not happy with the current solutions (making multiple ssh connections in a tabbed console).

So I made my own tool (similar to tmux).

https://github.com/osen/vimux

Dead simple to use, just extract and run bin/vimux. Or preferably add that bin folder to PATH to just run 'vimux'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.