Skip to content

Commit ab887d9

Browse files
authored
fix: indexing nil when env vars does not exist (#601)
1 parent 4c9bdf0 commit ab887d9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

lua/oil/clipboard.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ local M = {}
1010

1111
---@return "wayland"|"x11"|nil
1212
local function get_linux_session_type()
13-
local xdg_session_type = vim.env.XDG_SESSION_TYPE:lower()
13+
local xdg_session_type = vim.env.XDG_SESSION_TYPE
14+
if not xdg_session_type then
15+
return
16+
end
17+
xdg_session_type = xdg_session_type:lower()
1418
if xdg_session_type:find("x11") then
1519
return "x11"
1620
elseif xdg_session_type:find("wayland") then
@@ -23,7 +27,9 @@ end
2327
---@return boolean
2428
local function is_linux_desktop_gnome()
2529
local cur_desktop = vim.env.XDG_CURRENT_DESKTOP
26-
local idx = vim.env.XDG_SESSION_DESKTOP:lower():find("gnome") or cur_desktop:lower():find("gnome")
30+
local session_desktop = vim.env.XDG_SESSION_DESKTOP
31+
local idx = session_desktop and session_desktop:lower():find("gnome")
32+
or cur_desktop and cur_desktop:lower():find("gnome")
2733
return idx ~= nil or cur_desktop == "X-Cinnamon" or cur_desktop == "XFCE"
2834
end
2935

0 commit comments

Comments
 (0)