Use i3ipc for Python scripts
This commit is contained in:
parent
0d9eece16d
commit
cbdedf626d
@ -1,19 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import subprocess
|
||||
import json
|
||||
from itertools import groupby
|
||||
|
||||
workspaces = json.loads(
|
||||
subprocess.check_output(["i3-msg", "-t", "get_workspaces"]))
|
||||
import i3ipc
|
||||
|
||||
for tens, workspace_group in groupby(workspaces, lambda x: x['num'] // 10):
|
||||
i3 = i3ipc.Connection()
|
||||
workspaces = i3.get_workspaces()
|
||||
|
||||
for tens, workspace_group in groupby(workspaces, lambda ws: ws.num // 10):
|
||||
workspaces = [ws for ws in workspace_group
|
||||
if ws['num'] != -1 and ws['num'] % 10 != 0]
|
||||
if ws.num != -1 and ws.num % 10 != 0]
|
||||
|
||||
workspaces.sort(key=lambda x: x['num'])
|
||||
workspaces.sort(key=lambda ws: ws.num)
|
||||
for num, ws in enumerate(workspaces, 1):
|
||||
name = ws['name'].split(":")
|
||||
name = ws.name.split(":")
|
||||
name[0] = str(tens * 10 + num)
|
||||
subprocess.run(
|
||||
["i3", "rename", "workspace", ws['name'], "to", ":".join(name)])
|
||||
i3.command(f"rename workspace {ws.name} to {':'.join(name)}")
|
||||
|
@ -1,17 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import subprocess
|
||||
import json
|
||||
import re
|
||||
|
||||
workspaces = json.loads(
|
||||
subprocess.check_output(["i3-msg", "-t", "get_workspaces"]))
|
||||
focused = [ws for ws in workspaces if ws['focused']]
|
||||
import i3ipc
|
||||
|
||||
i3 = i3ipc.Connection()
|
||||
workspaces = i3.get_workspaces()
|
||||
focused = [ws for ws in workspaces if ws.focused]
|
||||
|
||||
if len(focused) == 1: # I have no idea when it wouldn't be, but whatever
|
||||
inputName = subprocess.check_output(
|
||||
['rofi', '-dmenu', '-l', '0', '-p', f'New name']).decode().strip()
|
||||
oldNum = str(focused[0]['num'])
|
||||
['rofi', '-dmenu', '-l', '0', '-p', 'New name']).decode().strip()
|
||||
oldNum = str(focused[0].num)
|
||||
|
||||
# basically either take raw input, allow clearing text part of a name,
|
||||
# or add input to current number
|
||||
@ -20,4 +21,4 @@ if len(focused) == 1: # I have no idea when it wouldn't be, but whatever
|
||||
oldNum if inputName == "" else \
|
||||
oldNum + ':' + inputName
|
||||
|
||||
subprocess.call(['i3', "rename", "workspace", "to", newName])
|
||||
i3.command(f"rename workspace to {newName}")
|
||||
|
Loading…
Reference in New Issue
Block a user