diff --git a/.config/i3/compact_workspace_numbers.py b/.config/i3/compact_workspace_numbers.py index 9754ec7..629d6c9 100755 --- a/.config/i3/compact_workspace_numbers.py +++ b/.config/i3/compact_workspace_numbers.py @@ -2,14 +2,18 @@ import subprocess import json +from itertools import groupby workspaces = json.loads( subprocess.check_output(["i3-msg", "-t", "get_workspaces"])) -workspaces = [ws for ws in workspaces if ws['num'] not in (-1, 10)] -workspaces.sort(key=lambda x: x['num']) -for num, ws in enumerate(workspaces, 1): - name = ws['name'].split(":") - name[0] = str(num) - subprocess.run( - ["i3", "rename", "workspace", ws['name'], "to", ":".join(name)]) +for tens, workspace_group in groupby(workspaces, lambda x: x['num'] // 10): + workspaces = [ws for ws in workspace_group + if ws['num'] != -1 and ws['num'] % 10 != 0] + + workspaces.sort(key=lambda x: x['num']) + for num, ws in enumerate(workspaces, 1): + name = ws['name'].split(":") + name[0] = str(tens * 10 + num) + subprocess.run( + ["i3", "rename", "workspace", ws['name'], "to", ":".join(name)])