From 38fa4e631fa5e6715e33de7cf78fd1f6a1c24717 Mon Sep 17 00:00:00 2001 From: Nizamuddin Sulieman Date: Sat, 9 Apr 2022 02:40:56 +0800 Subject: [PATCH 1/4] chore(wezterm): redo direction (WIP) --- config/wezterm/wezterm.lua | 61 +++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/config/wezterm/wezterm.lua b/config/wezterm/wezterm.lua index 90e7091a..d68a2499 100644 --- a/config/wezterm/wezterm.lua +++ b/config/wezterm/wezterm.lua @@ -216,6 +216,23 @@ on('ActivatePaneDirectionLeft', function(win, pane) switch_pane(win, pane, 'h') on('ActivatePaneDirectionUp', function(win, pane) switch_pane(win, pane, 'k') end) on('ActivatePaneDirectionDown', function(win, pane) switch_pane(win, pane, 'j') end) +local is_remote = function(pane) + local proc = basename(pane:get_foreground_process_name()) + wezterm.log_info('@is_remote, proc='..proc) + return proc == 'mosh' or proc == 'ssh' +end + +local direction = { + h = 'Left', + l = 'Right', + j = 'Down', + k = 'Up' +} + +local select_pane = function(win, pane, key) + -- code +end + return { default_prog = { '/opt/local/bin/zsh', '-li' }, @@ -342,6 +359,8 @@ return { -- define leader key, same as tmux leader = { key = 's', mods = 'CTRL', timeout_milliseconds = 1000 }, + disable_default_key_bindings = false, + -- mappings keys = { { key = 't', mods = hyper_key, action = action({ SpawnTab = 'CurrentPaneDomain' }) }, @@ -360,10 +379,35 @@ return { { key = 'k', mods = 'LEADER', action = action({ ActivatePaneDirection = 'Up' }) }, { key = 'j', mods = 'LEADER', action = action({ ActivatePaneDirection = 'Down' }) }, - { key = 'l', mods = 'CTRL', action = emit('ActivatePaneDirectionRight') }, - { key = 'h', mods = 'CTRL', action = emit('ActivatePaneDirectionLeft') }, - { key = 'k', mods = 'CTRL', action = emit('ActivatePaneDirectionUp') }, - { key = 'j', mods = 'CTRL', action = emit('ActivatePaneDirectionDown') }, + -- Pane movements + { key='h', mods="CTRL", action=wezterm.action_callback(function(win, pane) + if is_vim(pane) then + win:perform_action({ SendKey = { key = 'h', mods = 'CTRL' } }, pane) + else + win:perform_action({ ActivatePaneDirection = 'Left' }, pane) + end + end) }, + { key='l', mods="CTRL", action=wezterm.action_callback(function(win, pane) + if is_vim(pane) then + win:perform_action({ SendKey = { key = 'l', mods = 'CTRL' } }, pane) + else + win:perform_action({ ActivatePaneDirection = 'Right' }, pane) + end + end) }, + { key='j', mods="CTRL", action=wezterm.action_callback(function(win, pane) + if is_vim(pane) then + win:perform_action({ SendKey = { key = 'j', mods = 'CTRL' } }, pane) + else + win:perform_action({ ActivatePaneDirection = 'Down' }, pane) + end + end) }, + { key='k', mods="CTRL", action=wezterm.action_callback(function(win, pane) + if is_vim(pane) then + win:perform_action({ SendKey = { key = 'k', mods = 'CTRL' } }, pane) + else + win:perform_action({ ActivatePaneDirection = 'Up' }, pane) + end + end) }, { key = 'H', mods = 'LEADER', action = action({ AdjustPaneSize = { 'Left', 5 } }) }, { key = 'J', mods = 'LEADER', action = action({ AdjustPaneSize = { 'Down', 5 } }) }, @@ -372,6 +416,15 @@ return { { key = 'z', mods = 'LEADER', action = 'TogglePaneZoomState' }, { key = 'l', mods = 'LEADER|CTRL', action = action({ ClearScrollback = 'ScrollbackAndViewport' }) }, + { key='b', mods="LEADER", action=wezterm.action_callback(function(win, pane) + if is_remote(pane) then + win:perform_action({ SendKey = { key = 's', mods = 'CTRL' } }, pane) + else + wezterm.log_info('@is_remote, proc='..pane:get_foreground_process_name()) + -- win:perform_action({ ActivatePaneDirection = 'Left' }, pane) + end + end) }, + -- CTRL-SHIFT-l activates the debug overlay { key = 'L', mods = 'CTRL', action = action.ShowDebugOverlay }, }, From e5631b4a471105003577b179adba9fa9ead91376 Mon Sep 17 00:00:00 2001 From: Nizamuddin Sulieman Date: Thu, 21 Apr 2022 02:03:29 +0800 Subject: [PATCH 2/4] chore(wezterm): add logging --- config/wezterm/wezterm.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/config/wezterm/wezterm.lua b/config/wezterm/wezterm.lua index d68a2499..10d60c87 100644 --- a/config/wezterm/wezterm.lua +++ b/config/wezterm/wezterm.lua @@ -19,6 +19,15 @@ if use_webgpu then break end end + +local basename = function(s) return string.gsub(s, "(.*[/\\])(.*)", "%2") end + +local is_vim = function(pane) + wezterm.log_info('@is_vim, pane='..pane:get_foreground_process_name()) + local proc = basename(pane:get_foreground_process_name()) + wezterm.log_info('@is_vim, proc='..proc) + return proc == 'nvim' or proc == 'vim' + -- return string.match(proc, 'nvim') end local COLORS = { @@ -219,7 +228,7 @@ on('ActivatePaneDirectionDown', function(win, pane) switch_pane(win, pane, 'j') local is_remote = function(pane) local proc = basename(pane:get_foreground_process_name()) wezterm.log_info('@is_remote, proc='..proc) - return proc == 'mosh' or proc == 'ssh' + return proc == 'mosh-client' or proc == 'ssh' end local direction = { From c66b9b5aa618c39f7191696e1f2b843d6b391b8c Mon Sep 17 00:00:00 2001 From: Nizamuddin Sulieman Date: Wed, 3 Jul 2024 01:13:16 +0800 Subject: [PATCH 3/4] feat(wezterm): add more battery level info or running on power --- config/wezterm/wezterm.lua | 40 +++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/config/wezterm/wezterm.lua b/config/wezterm/wezterm.lua index 10d60c87..6f1716b9 100644 --- a/config/wezterm/wezterm.lua +++ b/config/wezterm/wezterm.lua @@ -191,13 +191,47 @@ wezterm.on('format-tab-title', function(tab) }) end) +-- Update right-status wezterm.on('update-status', function(window) local date = wezterm.strftime(' %a, %d %b %Y ') local time = wezterm.strftime(' %H:%M ') local batt = '' + local batt_soc = '' + local batt_state = '' + local batt_icon = nf.md_battery_unknown + local batt_charging = nf.md_lightning_bolt + local batt_info = '' + local _ = false + + -- wezterm.log_info('BATTERY: ', wezterm.battery_info()) + _, batt_info = pcall(wezterm.battery_info) + + if #batt_info > 0 then + for _, b in ipairs(batt_info) do + batt_state = b.state + batt_soc = b.state_of_charge * 100 + end + + batt = string.format(' %.0f%%', batt_soc) or '' + if batt_soc >= 95 then + batt_icon = nf.md_battery + elseif batt_soc >= 70 and batt_soc < 95 then + batt_icon = nf.md_battery_high + elseif batt_soc >= 35 and batt_soc < 70 then + batt_icon = nf.md_battery_medium + elseif batt_soc >= 5 and batt_soc < 40 then + batt_icon = nf.md_battery_low + elseif batt_soc < 5 then + batt_icon = nf.md_battery_outline + end - for _, b in ipairs(wezterm.battery_info()) do - batt = string.format(' %.0f%%', b.state_of_charge * 100) + if batt_state == 'Full' then + batt_icon = nf.md_battery + elseif batt_state == 'Charging' then + batt_icon = string.format('%s%s', batt_icon, batt_charging) + elseif batt_state == 'Unknown' then + batt_icon = nf.md_battery_alert + end end window:set_right_status(wezterm.format({ @@ -210,7 +244,7 @@ wezterm.on('update-status', function(window) { Text = nf.oct_clock }, { Text = time }, { Foreground = { Color = COLORS.maroon } }, - { Text = nf.md_battery_50 }, + { Text = (#batt_info > 0 and batt_icon or batt_charging) }, { Text = batt }, })) end) From 020bc83637ba7a34fd50fc1962d1242a1aafb06a Mon Sep 17 00:00:00 2001 From: Nizamuddin Sulieman Date: Wed, 3 Jul 2024 01:18:01 +0800 Subject: [PATCH 4/4] feat(wezterm): [wip] improve switching pane & process detection --- config/wezterm/wezterm.lua | 116 ++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 59 deletions(-) diff --git a/config/wezterm/wezterm.lua b/config/wezterm/wezterm.lua index 6f1716b9..64bf0e27 100644 --- a/config/wezterm/wezterm.lua +++ b/config/wezterm/wezterm.lua @@ -19,15 +19,6 @@ if use_webgpu then break end end - -local basename = function(s) return string.gsub(s, "(.*[/\\])(.*)", "%2") end - -local is_vim = function(pane) - wezterm.log_info('@is_vim, pane='..pane:get_foreground_process_name()) - local proc = basename(pane:get_foreground_process_name()) - wezterm.log_info('@is_vim, proc='..proc) - return proc == 'nvim' or proc == 'vim' - -- return string.match(proc, 'nvim') end local COLORS = { @@ -81,6 +72,8 @@ local switch_pane = function(win, pane, key) local direction = { h = 'Left', l = 'Right', j = 'Down', k = 'Up' } local proc = get_process(pane) + wezterm.log_info('@pane: TTY name, ttyp=' .. pane:get_tty_name()) + if is_vim(proc) or is_tmux(proc) then win:perform_action({ SendKey = { key = key, mods = 'CTRL' } }, pane) else @@ -88,6 +81,28 @@ local switch_pane = function(win, pane, key) end end +on('ActivatePaneDirectionRight', function(win, pane) switch_pane(win, pane, 'l') end) +on('ActivatePaneDirectionLeft', function(win, pane) switch_pane(win, pane, 'h') end) +on('ActivatePaneDirectionUp', function(win, pane) switch_pane(win, pane, 'k') end) +on('ActivatePaneDirectionDown', function(win, pane) switch_pane(win, pane, 'j') end) + +local is_remote = function(pane) + local proc = basename(pane:get_foreground_process_name()) + wezterm.log_info('@is_remote, proc='..proc) + return proc == 'mosh-client' or proc == 'ssh' +end + +local direction = { + h = 'Left', + l = 'Right', + j = 'Down', + k = 'Up' +} + +local select_pane = function(win, pane, key) + -- code +end + local function get_tab_process(tab) local process_icons = { nvim = { @@ -254,28 +269,6 @@ wezterm.on('window-config-reloaded', function(window, _) window:toast_notification('wezterm', 'configuration reloaded!', nil, 4000) end) -on('ActivatePaneDirectionRight', function(win, pane) switch_pane(win, pane, 'l') end) -on('ActivatePaneDirectionLeft', function(win, pane) switch_pane(win, pane, 'h') end) -on('ActivatePaneDirectionUp', function(win, pane) switch_pane(win, pane, 'k') end) -on('ActivatePaneDirectionDown', function(win, pane) switch_pane(win, pane, 'j') end) - -local is_remote = function(pane) - local proc = basename(pane:get_foreground_process_name()) - wezterm.log_info('@is_remote, proc='..proc) - return proc == 'mosh-client' or proc == 'ssh' -end - -local direction = { - h = 'Left', - l = 'Right', - j = 'Down', - k = 'Up' -} - -local select_pane = function(win, pane, key) - -- code -end - return { default_prog = { '/opt/local/bin/zsh', '-li' }, @@ -423,34 +416,39 @@ return { { key = 'j', mods = 'LEADER', action = action({ ActivatePaneDirection = 'Down' }) }, -- Pane movements - { key='h', mods="CTRL", action=wezterm.action_callback(function(win, pane) - if is_vim(pane) then - win:perform_action({ SendKey = { key = 'h', mods = 'CTRL' } }, pane) - else - win:perform_action({ ActivatePaneDirection = 'Left' }, pane) - end - end) }, - { key='l', mods="CTRL", action=wezterm.action_callback(function(win, pane) - if is_vim(pane) then - win:perform_action({ SendKey = { key = 'l', mods = 'CTRL' } }, pane) - else - win:perform_action({ ActivatePaneDirection = 'Right' }, pane) - end - end) }, - { key='j', mods="CTRL", action=wezterm.action_callback(function(win, pane) - if is_vim(pane) then - win:perform_action({ SendKey = { key = 'j', mods = 'CTRL' } }, pane) - else - win:perform_action({ ActivatePaneDirection = 'Down' }, pane) - end - end) }, - { key='k', mods="CTRL", action=wezterm.action_callback(function(win, pane) - if is_vim(pane) then - win:perform_action({ SendKey = { key = 'k', mods = 'CTRL' } }, pane) - else - win:perform_action({ ActivatePaneDirection = 'Up' }, pane) - end - end) }, + { key = 'h', mods = 'CTRL', action = emit('ActivatePaneDirectionLeft') }, + { key = 'l', mods = 'CTRL', action = emit('ActivatePaneDirectionRight') }, + { key = 'k', mods = 'CTRL', action = emit('ActivatePaneDirectionUp') }, + { key = 'j', mods = 'CTRL', action = emit('ActivatePaneDirectionDown') }, + + -- { key='h', mods="CTRL", action=wezterm.action_callback(function(win, pane) + -- if is_vim(pane) then + -- win:perform_action({ SendKey = { key = 'h', mods = 'CTRL' } }, pane) + -- else + -- win:perform_action({ ActivatePaneDirection = 'Left' }, pane) + -- end + -- end) }, + -- { key='l', mods="CTRL", action=wezterm.action_callback(function(win, pane) + -- if is_vim(pane) then + -- win:perform_action({ SendKey = { key = 'l', mods = 'CTRL' } }, pane) + -- else + -- win:perform_action({ ActivatePaneDirection = 'Right' }, pane) + -- end + -- end) }, + -- { key='j', mods="CTRL", action=wezterm.action_callback(function(win, pane) + -- if is_vim(pane) then + -- win:perform_action({ SendKey = { key = 'j', mods = 'CTRL' } }, pane) + -- else + -- win:perform_action({ ActivatePaneDirection = 'Down' }, pane) + -- end + -- end) }, + -- { key='k', mods="CTRL", action=wezterm.action_callback(function(win, pane) + -- if is_vim(pane) then + -- win:perform_action({ SendKey = { key = 'k', mods = 'CTRL' } }, pane) + -- else + -- win:perform_action({ ActivatePaneDirection = 'Up' }, pane) + -- end + -- end) }, { key = 'H', mods = 'LEADER', action = action({ AdjustPaneSize = { 'Left', 5 } }) }, { key = 'J', mods = 'LEADER', action = action({ AdjustPaneSize = { 'Down', 5 } }) },