Re-write compact workspaces script to be less stupid
This commit is contained in:
parent
cca40130b8
commit
53f2e6ade5
@ -3,18 +3,22 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
|
|
||||||
workspaces = json.loads(subprocess.run(["i3-msg", "-t", "get_workspaces"], stdout=subprocess.PIPE).stdout)
|
exclude_workspaces = (-1, 10)
|
||||||
numbered_workspaces = [ws for ws in workspaces if ws['num'] != -1]
|
|
||||||
#focused = next(ws for ws in workspaces if ws['focused'] == True)
|
def numbered_workspaces():
|
||||||
maximum_ws = max(numbered_workspaces, key=lambda ws: ws['num'])
|
workspaces = json.loads(subprocess.run(["i3-msg", "-t", "get_workspaces"],
|
||||||
# loop through all possible workspace numbers
|
stdout=subprocess.PIPE).stdout)
|
||||||
for ws_num in range(1, maximum_ws['num']):
|
return {int(ws['num']): ws for ws in workspaces if ws['num'] not in exclude_workspaces}
|
||||||
# if workspace with current number doesn't exist
|
|
||||||
# TODO: handle multiple missing workspaces (consecutive or not)
|
workspaces = sorted(numbered_workspaces().keys())
|
||||||
if next((ws for ws in numbered_workspaces if ws['num'] == ws_num), None) is None:
|
num = 1
|
||||||
# loop through all greater numbers and move down 1
|
print(workspaces)
|
||||||
for ws in [ws for ws in numbered_workspaces if ws['num'] > ws_num]:
|
while len(workspaces) > 0:
|
||||||
new_name = ws['name'].split(":")
|
ws = numbered_workspaces()[workspaces.pop(0)]
|
||||||
new_name[0] = str(int(new_name[0]) - 1) # subtract 1 from workspace number
|
if ws['num'] != num:
|
||||||
subprocess.run(["i3-msg", "rename", "workspace",
|
new_name = ws['name'].split(":")
|
||||||
ws['name'], "to", ":".join(new_name)])
|
new_name[0] = str(num)
|
||||||
|
print("move", ws['num'], '->', num)
|
||||||
|
subprocess.run(["i3-msg", "rename", "workspace",
|
||||||
|
ws['name'], "to", ":".join(new_name)])
|
||||||
|
num += 1
|
||||||
|
Loading…
Reference in New Issue
Block a user