Skip to content

Instantly share code, notes, and snippets.

@frangio
Created August 14, 2015 06:13
Show Gist options
  • Save frangio/90f9d806db766ba4c40c to your computer and use it in GitHub Desktop.
Save frangio/90f9d806db766ba4c40c to your computer and use it in GitHub Desktop.
Lua script to switch to next empty workspace in i3wm. Depends on i3ipc-lua.
#!/usr/bin/env lua
i3ipc = require 'i3ipc'
conn = i3ipc.Connection()
tree = conn:get_tree()
ws = {}
for _, w in pairs(tree:workspaces()) do
if w.focused then
conn:command('workspace ' .. w.name)
os.exit(true, true)
end
ws[w.name] = true
end
curr = tonumber(tree:find_focused():workspace().name)
if not curr then
curr = 1
end
for w = curr+1, curr+9 do
w = (w - 1) % 10 + 1
if not ws[tostring(w)] then
conn:command('workspace ' .. w)
os.exit(true, true)
end
end
os.exit(false, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment