-
Notifications
You must be signed in to change notification settings - Fork 12
/
i3-color-rofi
executable file
·87 lines (76 loc) · 2.69 KB
/
i3-color-rofi
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# Fetches the current i3 wm colors and provides an options string to color rofi
# Usage: rofi <your-options> $(i3-color-rofi)
# by Oliver Kraitschy - http://okraits.de
from os import getenv
# SETTINGS
config_path = getenv("HOME") + "/.i3/config"
# variables
config_file = None
lines = None
normal_bg = None
normal_fg = None
selected_bg = None
selected_fg = None
normal_bg_var = False
normal_fg_var = False
selected_bg_var = False
selected_fg_var = False
cmd_string = ""
if __name__ == "__main__":
# open config file
try:
config_file = open(config_path, "r")
except IOError:
print("Error: i3 config file could not be opened.")
exit(1)
# read all lines into a list
lines = config_file.readlines()
config_file.close()
# loop over lines and find matches
for line in lines:
cols = line.split()
# for all lines not empty
if len(cols) > 0:
# normal background
if cols[0] == "client.unfocused":
normal_bg = cols[2]
if normal_bg[0] == "$":
normal_bg_var = True
# normal foreground
normal_fg = cols[3]
if normal_fg[0] == "$":
normal_fg_var = True
# selected background
if cols[0] == "client.focused":
selected_bg = cols[2]
if selected_bg[0] == "$":
selected_bg_var = True
# selected foreground
selected_fg = cols[3]
if selected_fg[0] == "$":
selected_fg_var = True
# at least one variable was used, we need to find the real values
if normal_bg_var or normal_fg_var or selected_bg_var or selected_fg_var:
for line in lines:
cols = line.split()
# for all lines starting with "set"
if len(cols) > 0 and cols[0] == "set":
if normal_bg_var and cols[1] == normal_bg:
normal_bg = cols[2]
if normal_fg_var and cols[1] == normal_fg:
normal_fg = cols[2]
if selected_bg_var and cols[1] == selected_bg:
selected_bg = cols[2]
if selected_fg_var and cols[1] == selected_fg:
selected_fg = cols[2]
if normal_bg is not None:
cmd_string += "-bg " + normal_bg + " "
if normal_fg is not None:
cmd_string += "-fg " + normal_fg + " "
if selected_bg is not None:
cmd_string += "-hlbg " + selected_bg + " "
if selected_fg is not None:
cmd_string += "-hlfg " + selected_fg + " "
print(cmd_string)
exit(0)