sum*_*mek 36 windows cygwin powershell tmux
是否有替代 tmux/screen 的方法可以在 Windows 上使用 Powershell?我知道 Powerscreen,但它似乎已经死了很长时间。Cygwin 不能与 Powershell 一起使用,是吗?Console2是很普城域网解决方案。
还有什么想法吗?
Not*_*1ds 20
尽管最初提出这个问题时这是不可能的,但通过适用于 Linux 的 Windows 子系统,现在可以使用“真正的”tmux来管理 PowerShell 窗口。
在已安装的 WSL 实例中tmux,设置~/.tmux.conf:
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"
Run Code Online (Sandbox Code Playgroud)
您通常期望的大多数功能tmux,包括:
有多种方法可以进行设置,但我目前的做法如下:
安装适用于 Linux 的 Windows 子系统。您不必启用 WSL2;仅 WSL v1 就可以很好地解决此问题(也许比 WSL2 更好)。
安装 Alpine Linux 发行版。我使用它作为 tmux 功能的基础,因为它的开销非常低(小于 12MB,包括tmux)。
接下来的几个步骤是可选的。我为 PowerShell tmux 创建一个新的克隆 WSL 实例。您可以只使用默认的 Alpine 实例,但我喜欢使用单一用途的 WSL 实例,类似于 Docker 容器。
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
Run Code Online (Sandbox Code Playgroud)
以 root 身份启动 WSL 实例wsl -d posh_tmux -u root
adduser tmux,并给它一个密码。
/etc/wsl.conf通过使用以下内容创建来设置实例的默认用户:
[user]
default = tmux
Run Code Online (Sandbox Code Playgroud)
apk add tmux安装tmux
退出会话,重新启动wsl ~ -d tmux(省略用户名,因为它现在默认为 tmux 用户)
~/.tmux.conf使用以下内容创建一个:
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"
Run Code Online (Sandbox Code Playgroud)
~/.profile使用以下内容创建一个:
if tmux has-session -t=posh; then
exec tmux attach-session -t posh
else
exec tmux new-session -s posh -n PowerShell
fi
Run Code Online (Sandbox Code Playgroud)
PowerShell Core tmux在 Windows 终端、ConEmu 或您喜欢的任何方式中设置配置文件。启动命令很简单wsl -d tmux_posh
如果您需要在不输入 tmux/PowerShell 的情况下访问实例(例如,编辑sudo apk upgrade配置),请使用wsl ~ -d tmux_posh -e sh(或wsl ~ -d tmux_posh -u root) 启动。
您可以tmux通过以下方式从 PowerShell 中访问命令wsl -d tmux_posh -e tmux <tmux_command。例如,wsl -d tmux_posh -e tmux rename-window host1。tmuxTODO:为此创建一个包装器 PowerShell 函数。
TODO:PowerShell提示功能将窗口名称动态设置为最后执行的命令
小智 9
它并不完全类似于 tmux 或 screen,但 PowerShell 具有管理远程会话的功能。Ed Wilson 写了一篇关于它的博客文章,标题为Learn How to Manage Remote PowerShell Sessions,这可能会有所帮助。另请参阅about_PSSessions PowerShell 帮助主题。
你能说更多关于你正在努力实现的目标吗?
小智 7
试试 Cmder。这很棒!它甚至与适用于 Windows 的 git 捆绑在一起。 http://cmder.net/
我已经有一段时间没有使用 Windows 了,但刚刚发现https://wezfurlong.org/wezterm/features.html,它非常适合我的要求
除其他外,它还有选项卡和垂直/水平分割
| 归档时间: |
|
| 查看次数: |
36359 次 |
| 最近记录: |