From 9b0261fec0216953322ac8a521ca887e68bd1744 Mon Sep 17 00:00:00 2001 From: Nulo Date: Mon, 13 Jun 2022 12:49:25 -0300 Subject: [PATCH] sway-rename-workspace --- .local/bin/sway-rename-workspace | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 .local/bin/sway-rename-workspace diff --git a/.local/bin/sway-rename-workspace b/.local/bin/sway-rename-workspace new file mode 100755 index 0000000..8034bd2 --- /dev/null +++ b/.local/bin/sway-rename-workspace @@ -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.."'"))