-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi3wsrename
executable file
·47 lines (35 loc) · 1.18 KB
/
i3wsrename
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
"""
Rename the current workspace according to user's answer to a GUI prompt.
Requirements:
sudo apt install zenity
"""
import subprocess
import json
from functools import cache
@cache
def current_workspace():
d = json.loads(subprocess.check_output(['i3-msg', '-t', 'get_workspaces'],
encoding='utf-8'))
for s in d:
if s['focused']:
return s['num'], s['name']
raise KeyError('Could not find currently focused workspace.')
def rename(old_name, new_name):
subprocess.run(
['i3-msg', f'rename workspace {old_name} to {new_name}'])
def get_desired_name():
"""Prompts the user for the desired ws name, and prepend the ws number.
"""
num, _ = current_workspace()
name = subprocess.check_output(["zenity", "--entry", "--width", "500" ,"--title",
"Workspace name" , "--text", "Enter the desired workspace name"],
encoding='utf-8')
new_name = f'{num}:{name}'.strip().removesuffix(':')
return new_name
def main():
_, curr_name = current_workspace()
new_name = get_desired_name()
rename(curr_name, new_name)
if __name__ == '__main__':
main()