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

wezterm 自动读取 ssh 配置文件 #82

Open
hanxi opened this issue Apr 29, 2022 · 0 comments
Open

wezterm 自动读取 ssh 配置文件 #82

hanxi opened this issue Apr 29, 2022 · 0 comments

Comments

@hanxi
Copy link
Owner

hanxi commented Apr 29, 2022

wezterm 是采用 Rust 实现和 Lua 配置的终端软件,我之前一段时间都是使用 Windows terminal ,发现 wezterm 是采用 Lua 配置的,很方便自定义功能。比如之前给 Windows terminal 提过的一个很小的需求,像 vscode 一样自动读取 .ssh/config 文件的主机配置 ,然而却却迟迟没有实现,Windows terminal 采用 JSON 配置的(如果是 JavaScript 的话还有可能),不能像 wezterm 一样使用 Lua 语言一样能动态生成配置。

下面几行配置就能实现自动读取 ssh 的配置文件,生成主机列表供选择进入,而且 wezterm 的启动菜单是支持查找的,这样只要主机名定义的有规范,就可以方便搜索进入了,就能更方便的作为远程主机管理工具了。wezterm 的配置文档也挺齐全的,参考 wezterm/config/launch

local wezterm = require "wezterm"

local launch_menu = {}

local ssh_config_file = wezterm.home_dir .. "/.ssh/config"
local f = io.open(ssh_config_file)
if f then
    local line = f:read("*l")
    while line do
        if line:find("Host ") == 1 then
            local host = line:gsub("Host ", "")
            table.insert(
                launch_menu,
                {
                    label = "SSH " .. host,
                    args = {"powershell.exe", "ssh", host}
                }
            )
        end
        line = f:read("*l")
    end
    f:close()
end

return {
    launch_menu = launch_menu,
}

我的完整配置见 https://github.com/hanxi/dotfiles/blob/master/etc/wezterm/wezterm.lua ,加入了些主题配置。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant