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

pane:get_foreground_process_name() is returning nil #3995

Closed
mhanberg opened this issue Jul 14, 2023 · 4 comments
Closed

pane:get_foreground_process_name() is returning nil #3995

mhanberg opened this issue Jul 14, 2023 · 4 comments
Labels
bug Something isn't working macOS Issue applies to Apple macOS waiting-on-op Waiting for more information from the original poster

Comments

@mhanberg
Copy link

What Operating System(s) are you seeing this problem on?

macOS

Which Wayland compositor or X11 Window manager(s) are you using?

No response

WezTerm version

wezterm 20230713-174400-115e629e

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

I think this might have something to do with the macOS security response update that I installed this morning, but now my navigation between vim splits and wezterm splits isn't working, and it seems to be breaking on pane:get_foreground_process_name, which is returning nil

To Reproduce

No response

Configuration

local wezterm = require("wezterm")
local home = "/Users/mitchell"
local icloud = string.format("%s/Library/Mobile Documents/com~apple~CloudDocs", home)
local src = string.format("%s/src", home)

local table_filter = function(tbl, filterer)
  local new_table = {}

  for _, el in ipairs(tbl) do
    if filterer(el) then
      table.insert(new_table, el)
    end
  end

  return new_table
end

local function isViProcess(pane)
  -- get_foreground_process_name On Linux, macOS and Windows,
  -- the process can be queried to determine this path. Other operating systems
  -- (notably, FreeBSD and other unix systems) are not currently supported
  return pane:get_foreground_process_name():find("n?vim") ~= nil
  -- return pane:get_title():find("n?vim") ~= nil
end

local function conditionalActivatePane(window, pane, pane_direction, vim_direction)
  if isViProcess(pane) then
    window:perform_action(wezterm.action.SendKey { key = "w", mods = "CTRL" }, pane)
    window:perform_action(wezterm.action.SendKey { key = vim_direction }, pane)
  else
    window:perform_action(wezterm.action.ActivatePaneDirection(pane_direction), pane)
  end
end

wezterm.on("ActivatePaneDirection-right", function(window, pane)
  conditionalActivatePane(window, pane, "Right", "l")
end)
wezterm.on("ActivatePaneDirection-left", function(window, pane)
  conditionalActivatePane(window, pane, "Left", "h")
end)
wezterm.on("ActivatePaneDirection-up", function(window, pane)
  conditionalActivatePane(window, pane, "Up", "k")
end)
wezterm.on("ActivatePaneDirection-down", function(window, pane)
  conditionalActivatePane(window, pane, "Down", "j")
end)
wezterm.on("user-var-changed", function(window, pane, name, value)
  if name == "WORKSPACE_CHANGED" and string.len(value) > 0 then
    wezterm.log_info(name, value, "/Users/mitchell/src/" .. value)
    local cwd
    if value == ".dotfiles" then
      cwd = "/Users/mitchell/.dotfiles"
    elseif value == "notes" then
      cwd = string.format("%s/%s", icloud, "notes/personal")
    elseif value == "work-notes" then
      cwd = string.format("%s/%s", icloud, "notes/work")
    else
      cwd = string.format("%s/%s", src, value)
    end

    wezterm.GLOBAL.last_open_workspace = window:active_workspace()

    window:perform_action(
      wezterm.action.SwitchToWorkspace {
        name = value,
        spawn = {
          cwd = cwd,
        },
      },
      pane
    )
  end
end)

wezterm.on("fzf-workspaces-open", function(window)
  window:mux_window():spawn_tab {
    args = { "/Users/mitchell/.bin/wezterm-workspace-fzf" },
  }
end)

wezterm.on("fzf-workspaces-switch", function(window)
  window:mux_window():spawn_tab {
    args = { "/Users/mitchell/.bin/wezterm-switch-workspace" },
    set_environment_variables = {
      FZF_DEFAULT_COMMAND = string.format(
        "echo '%s'",
        table.concat(
          table_filter(wezterm.mux.get_workspace_names(), function(n)
            return n ~= window:active_workspace()
          end),
          "\n"
        )
      ),
    },
  }
end)

return {
  term = "wezterm",
  unix_domains = { { name = "unix" } },
  default_gui_startup_args = { "connect", "unix" },
  font = wezterm.font("JetBrainsMono Nerd Font Mono"),
  font_size = 14.0,
  color_scheme = "kanagawa_dragon",
  front_end = "WebGpu",
  inactive_pane_hsb = {
    saturation = 1.0,
    brightness = 1.0,
  },
  skip_close_confirmation_for_processes_named = { "" },
  tab_bar_at_bottom = true,
  switch_to_last_active_tab_when_closing_tab = true,
  leader = { key = "s", mods = "CTRL", timeout_milliseconds = 1000 },
  keys = {
    { key = "y", mods = "CMD", action = wezterm.action { EmitEvent = "fzf-workspaces-open" } },
    { key = "j", mods = "CMD", action = wezterm.action { EmitEvent = "fzf-workspaces-switch" } },
    {
      key = "m",
      mods = "CMD",
      action = wezterm.action {
        SpawnCommandInNewTab = {
          args = { "lazygit" },
          set_environment_variables = {
            PATH = "/opt/homebrew/bin:" .. os.getenv("PATH"),
            XDG_CONFIG_HOME = string.format("%s/%s", home, ".config"),
          },
        },
      },
    },
    {
      key = "h",
      mods = "CMD",
      action = wezterm.action {
        SpawnCommandInNewTab = {
          args = { "fzf-prs" },
          set_environment_variables = {
            PATH = string.format("%s/%s", home, ".bin:") .. "/opt/homebrew/bin:" .. os.getenv("PATH"),
          },
        },
      },
    },
    {
      key = "l",
      mods = "CMD",
      action = wezterm.action_callback(function(window, pane)
        local last = wezterm.GLOBAL.last_open_workspace
        wezterm.GLOBAL.last_open_workspace = window:active_workspace()
        window:perform_action(wezterm.action.SwitchToWorkspace { name = last }, pane)
      end),
    },

    { key = "t", mods = "CMD", action = wezterm.action { SpawnTab = "CurrentPaneDomain" } },
    -- { key = "j", mods = "LEADER", action = wezterm.action { SpawnTab = { DomainName = "dotfiles" } } },
    { key = "]", mods = "CMD", action = wezterm.action { ActivateTabRelative = 1 } },
    { key = "[", mods = "CMD", action = wezterm.action { ActivateTabRelative = -1 } },
    {
      key = "\\",
      mods = "CMD",
      action = wezterm.action { SplitHorizontal = { domain = "CurrentPaneDomain" } },
    },
    {
      key = "-",
      mods = "LEADER",
      action = wezterm.action { SplitVertical = { domain = "CurrentPaneDomain" } },
    },
    { key = "w", mods = "CMD", action = wezterm.action { CloseCurrentPane = { confirm = true } } },
    { key = "h", mods = "CTRL", action = wezterm.action.EmitEvent("ActivatePaneDirection-left") },
    { key = "j", mods = "CTRL", action = wezterm.action.EmitEvent("ActivatePaneDirection-down") },
    { key = "k", mods = "CTRL", action = wezterm.action.EmitEvent("ActivatePaneDirection-up") },
    { key = "l", mods = "CTRL", action = wezterm.action.EmitEvent("ActivatePaneDirection-right") },
    { key = "d", mods = "CMD", action = "ShowDebugOverlay" },
  },
}

Expected Behavior

No response

Logs

09:48:26.672 ERROR wezterm_gui::termwindow > while processing ActivatePaneDirection-left event: runtime error: [string "/Users/mitchell/.config/wezterm/wezterm.lua"]:22: attempt to index a nil value
stack traceback:
        [string "/Users/mitchell/.config/wezterm/wezterm.lua"]:22: in upvalue 'isViProcess'
        [string "/Users/mitchell/.config/wezterm/wezterm.lua"]:27: in upvalue 'conditionalActivatePane'
        [string "/Users/mitchell/.config/wezterm/wezterm.lua"]:39: in function <[string "/Users/mitchell/.config/wezterm/wezterm.lua"]:38>

Anything else?

No response

@mhanberg mhanberg added the bug Something isn't working label Jul 14, 2023
@wez wez added the macOS Issue applies to Apple macOS label Jul 14, 2023
@mhanberg
Copy link
Author

There might be other effects from this macOS update.

today i experienced lots of weirdness with pane and window resizing. either from changing the window size through macos shortcuts or creating a new split pane. the resulting panes would odd sizes or seem like it was extended beyond the screen

@wez
Copy link
Owner

wez commented Feb 6, 2024

Please try the latest release

@wez wez added the waiting-on-op Waiting for more information from the original poster label Feb 6, 2024
Copy link
Contributor

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working macOS Issue applies to Apple macOS waiting-on-op Waiting for more information from the original poster
Projects
None yet
Development

No branches or pull requests

2 participants