From 96ae753a2924a8a16b508bc2d99ae5023e2a5788 Mon Sep 17 00:00:00 2001 From: Oliver Kraitschy Date: Sun, 4 Jan 2015 00:09:50 +0100 Subject: [PATCH] Initial commit. --- README.md | 40 +++++++++++++++++++++++ i3-color-rofi | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 README.md create mode 100755 i3-color-rofi diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b433c6 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +## i3-color-rofi + +#### Color rofi similar to your i3 wm + +### Overview + +Fetches the current i3 wm colors and provides an options string to color rofi + +### Requirements + +i3-color-rofi has the following requirements: + +- Python 2 or 3 + +### Usage + +Append it to your rofi command line: + + rofi $(i3-color-rofi) + +i3-color-rofi generates an options string, for example: + + -bg #222222 -fg #888888 -hlbg #285577 -hlfg #ffffff + +So your resulting command line may be: + + rofi -rnow -bg #222222 -fg #888888 -hlbg #285577 -hlfg #ffffff + +### Installation + +Place *i3-color-rofi* anywhere in your $PATH, for example in +*/home/yourUserName/bin*, and ensure that it is executable. Set the path +to the i3 config file in the script. Use it. + +### License + +This software is released under the terms of the +GNU General Public License v2: + +[http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt](http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt) diff --git a/i3-color-rofi b/i3-color-rofi new file mode 100755 index 0000000..12577d4 --- /dev/null +++ b/i3-color-rofi @@ -0,0 +1,87 @@ +#!/usr/bin/python + +# Fetches the current i3 wm colors and provides an options string to color rofi +# Usage: rofi $(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)