sway-rename-workspace

This commit is contained in:
Cat /dev/Nulo 2022-06-13 12:49:25 -03:00
parent 4237e7954d
commit 9b0261fec0

View file

@ -0,0 +1,24 @@
#!/usr/bin/env lua5.1
-- https://stackoverflow.com/a/326715
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
local rename_to = os.capture("echo | fuzzel-run --dmenu")
local workspace_number = os.capture("swaymsg -t get_workspaces | jq '.[] | select(.focused).num'")
local workspace_new_name = workspace_number .. ": " .. rename_to
if #rename_to == 0 then
workspace_new_name = workspace_number
end
assert(os.execute("swaymsg rename workspace to '"..workspace_new_name.."'"))