Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env lua
- function string.split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t = {}
- for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
- table.insert(t, str)
- end
- return t
- end
- local xprop = io.popen("xprop")
- local whoami = io.popen("whoami")
- local username = whoami:read("*a"):sub(1, -2)
- local shit = xprop:read("*a")
- whoami:close()
- xprop:close()
- local done = false
- local wm_class
- -- get the wm class
- for i, v in pairs(shit:split("\n")) do
- if v:find("WM_CLASS") then
- wm_class = v:sub(20):split(",")
- done = true
- break
- end
- end
- if not done then
- error("Couldn't get window class")
- end
- wm_class = wm_class[2]:sub(2, -1)
- local i3_config_path = string.format("/home/%s/.config/i3/config", username)
- local floating_windows_path = string.format("/home/%s/.config/i3/floating_windows.conf", username)
- local i3_config = io.open(i3_config_path, "r")
- local floating_windows = io.open(floating_windows_path, "r")
- if not i3_config then
- error("i3 config doesn't exist. checked file: ~/.config/i3/config")
- end
- if not floating_windows then
- os.execute("touch ~/.config/i3/floating_windows.conf")
- floating_windows = io.open(floating_windows_path, "rw")
- if not floating_windows then
- error("failed to create floating_windows.conf")
- end
- end
- local should_append_config = true
- for i, v in pairs(i3_config:read("a"):split("\n")) do
- if v:find("include") and v:find("floating_windows%.conf") then
- should_append_config = false
- end
- end
- if should_append_config then
- os.execute('echo "" >> ~/.config/i3/config')
- os.execute('echo "# autogenerated" >> ~/.config/i3/config')
- os.execute('echo "include ~/.config/i3/floating_windows.conf" >> ~/.config/i3/config')
- print("... appended i3 config")
- end
- os.execute(
- string.format('echo "for_window [class=\\"%s\\"] floating enable" >> ~/.config/i3/floating_windows.conf', wm_class)
- )
- floating_windows:close()
- print("... registered floating window:", wm_class)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement