Skip to content

Instantly share code, notes, and snippets.

@kontza
Last active January 8, 2024 09:24
Show Gist options
  • Select an option

  • Save kontza/7ee30f5ed7ae949e90bd03bc0d8bc63d to your computer and use it in GitHub Desktop.

Select an option

Save kontza/7ee30f5ed7ae949e90bd03bc0d8bc63d to your computer and use it in GitHub Desktop.

Revisions

  1. kontza revised this gist Jan 8, 2024. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions snippet-wezterm.lua
    Original file line number Diff line number Diff line change
    @@ -12,20 +12,20 @@ wezterm.on("update-status", function(window, pane)
    for ndx = 2, #fg.argv do
    for k, v in pairs(host_to_color) do
    if string.find(fg.argv[ndx], k) then
    if not colored_panes[pane.pane_id] then
    if not colored_panes[pane:pane_id()] then
    -- print(">>> NEW")
    pane:inject_output(string.format("\x1b]11;%s\x07", string.sub(v, 2)))
    colored_panes[pane.pane_id] = fg.pid
    colored_panes[pane:pane_id()] = fg.pid
    end
    end
    end
    end
    else
    if colored_panes[pane.pane_id] then
    local ssh = wezterm.procinfo.get_info_for_pid(colored_panes[pane.pane_id])
    if colored_panes[pane:pane_id()] then
    local ssh = wezterm.procinfo.get_info_for_pid(colored_panes[pane:pane_id()])
    if not ssh then
    -- print(">>> CLEARED")
    colored_panes[pane.pane_id] = nil
    colored_panes[pane:pane_id()] = nil
    pane:inject_output("\x1b]104\x07")
    end
    end
  2. kontza revised this gist Jan 8, 2024. 1 changed file with 25 additions and 25 deletions.
    50 changes: 25 additions & 25 deletions snippet-wezterm.lua
    Original file line number Diff line number Diff line change
    @@ -1,33 +1,33 @@
    -- Hash char is here to make good editors show the color in situ.
    local host_to_color = {
    ["main.*p"] = "#660000",
    ["other.*q"] = "#660066",
    ["main.*p"] = "#660000",
    ["other.*q"] = "#660066",
    -- key = a pattern to match a hostname
    -- value = the color to use as pane background for the hostname
    }
    local colored_panes = {}
    wezterm.on("update-status", function(window, pane)
    local fg = pane:get_foreground_process_info() or {}
    if fg.name == "ssh" then
    for ndx = 2, #fg.argv do
    for k, v in pairs(host_to_color) do
    if string.find(fg.argv[ndx], k) then
    if not colored_panes[pane.pane_id] then
    -- print(">>> NEW")
    pane:inject_output(string.format("\x1b]11;%s\x07", string.sub(v, 2)))
    colored_panes[pane.pane_id] = fg.pid
    end
    end
    end
    end
    else
    if colored_panes[pane.pane_id] then
    local ssh = wezterm.procinfo.get_info_for_pid(colored_panes[pane.pane_id])
    if not ssh then
    -- print(">>> CLEARED")
    colored_panes[pane.pane_id] = nil
    pane:inject_output("\x1b]104\x07")
    end
    end
    end
    local fg = pane:get_foreground_process_info() or {}
    if fg.name == "ssh" then
    for ndx = 2, #fg.argv do
    for k, v in pairs(host_to_color) do
    if string.find(fg.argv[ndx], k) then
    if not colored_panes[pane.pane_id] then
    -- print(">>> NEW")
    pane:inject_output(string.format("\x1b]11;%s\x07", string.sub(v, 2)))
    colored_panes[pane.pane_id] = fg.pid
    end
    end
    end
    end
    else
    if colored_panes[pane.pane_id] then
    local ssh = wezterm.procinfo.get_info_for_pid(colored_panes[pane.pane_id])
    if not ssh then
    -- print(">>> CLEARED")
    colored_panes[pane.pane_id] = nil
    pane:inject_output("\x1b]104\x07")
    end
    end
    end
    end)
  3. kontza revised this gist Jan 8, 2024. No changes.
  4. kontza revised this gist Jan 8, 2024. No changes.
  5. kontza created this gist Jan 8, 2024.
    33 changes: 33 additions & 0 deletions snippet-wezterm.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    -- Hash char is here to make good editors show the color in situ.
    local host_to_color = {
    ["main.*p"] = "#660000",
    ["other.*q"] = "#660066",
    -- key = a pattern to match a hostname
    -- value = the color to use as pane background for the hostname
    }
    local colored_panes = {}
    wezterm.on("update-status", function(window, pane)
    local fg = pane:get_foreground_process_info() or {}
    if fg.name == "ssh" then
    for ndx = 2, #fg.argv do
    for k, v in pairs(host_to_color) do
    if string.find(fg.argv[ndx], k) then
    if not colored_panes[pane.pane_id] then
    -- print(">>> NEW")
    pane:inject_output(string.format("\x1b]11;%s\x07", string.sub(v, 2)))
    colored_panes[pane.pane_id] = fg.pid
    end
    end
    end
    end
    else
    if colored_panes[pane.pane_id] then
    local ssh = wezterm.procinfo.get_info_for_pid(colored_panes[pane.pane_id])
    if not ssh then
    -- print(">>> CLEARED")
    colored_panes[pane.pane_id] = nil
    pane:inject_output("\x1b]104\x07")
    end
    end
    end
    end)