-
Notifications
You must be signed in to change notification settings - Fork 2
/
meta_workspaces.py
53 lines (44 loc) · 1.43 KB
/
meta_workspaces.py
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
48
49
50
51
52
53
import os
import argparse
from subprocess import call
#Handle flags
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--meta", help="Meta flag")
parser.add_argument("-w", "--workspace", help="Workspace flag")
parser.add_argument("-mw", "--move_window", help="Move flag")
args = parser.parse_args()
#Name of stored meta variable
metaVarName = "meta_workspace"
#Correct path to stored variable
dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, 'variables')
def readMeta():
with open(filename) as fin:
for line in fin:
if line.startswith(metaVarName):
return line.split(":")[-1].strip()
def writeMeta(value):
if os.path.isfile(filename):
os.remove(filename)
with open(filename, 'a') as out:
out.write(metaVarName + ":" + value + '\n')
#Create file if it does not exist
if not os.path.isfile(filename):
writeMeta("0")
#Change meta workspace
if args.meta is not None:
meta = args.meta
writeMeta(meta)
#Change workspace within meta workspace
if args.workspace is not None:
meta = readMeta()
workspace = args.workspace
print(meta)
cmd = 'i3-msg "workspace ' + meta + workspace + ';"'
os.system(cmd)
#Move window in between workspaces within meta workspace
if args.move_window is not None:
meta = readMeta()
workspace = args.move_window
cmd = 'i3-msg "move container to workspace ' + meta + workspace + ';"'
os.system(cmd)