d1dbccc5f9490ccb4c6a76c1817e500229bc44c3
[screen-lua.git] / src / scripts / findwindow.lua
blobd1dbccc5f9490ccb4c6a76c1817e500229bc44c3
1 function find_window(name)
2 display = screen.display()
3 canvases = {display:get_canvases()}
4 for i, c in pairs(canvases) do
5 w = c.window
6 if w ~= nil and (w.title == name or tostring(w.number) == name) then c:select() return end
7 end
9 -- Try partial matches, just like 'select'
10 for i, c in pairs(canvases) do
11 w = c.window
12 if w ~= nil and w.title:sub(1, name:len()) == name then c:select() return end
13 end
15 -- We didn't find the desired window in any canvas
16 -- So switch to the window in the current canvas instead
17 screen.command("select " .. name)
18 end