Advertisement
theblackshibe

Untitled

Sep 29th, 2022
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #!/usr/bin/env lua
  2.  
  3. function string.split(inputstr, sep)
  4. if sep == nil then
  5. sep = "%s"
  6. end
  7. local t = {}
  8. for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
  9. table.insert(t, str)
  10. end
  11. return t
  12. end
  13.  
  14. local xprop = io.popen("xprop")
  15. local whoami = io.popen("whoami")
  16. local username = whoami:read("*a"):sub(1, -2)
  17. local shit = xprop:read("*a")
  18.  
  19. whoami:close()
  20. xprop:close()
  21.  
  22. local done = false
  23. local wm_class
  24.  
  25. -- get the wm class
  26. for i, v in pairs(shit:split("\n")) do
  27. if v:find("WM_CLASS") then
  28. wm_class = v:sub(20):split(",")
  29. done = true
  30.  
  31. break
  32. end
  33. end
  34.  
  35. if not done then
  36. error("Couldn't get window class")
  37. end
  38.  
  39. wm_class = wm_class[2]:sub(2, -1)
  40.  
  41. local i3_config_path = string.format("/home/%s/.config/i3/config", username)
  42. local floating_windows_path = string.format("/home/%s/.config/i3/floating_windows.conf", username)
  43.  
  44. local i3_config = io.open(i3_config_path, "r")
  45. local floating_windows = io.open(floating_windows_path, "r")
  46.  
  47. if not i3_config then
  48. error("i3 config doesn't exist. checked file: ~/.config/i3/config")
  49. end
  50.  
  51. if not floating_windows then
  52. os.execute("touch ~/.config/i3/floating_windows.conf")
  53. floating_windows = io.open(floating_windows_path, "rw")
  54. if not floating_windows then
  55. error("failed to create floating_windows.conf")
  56. end
  57. end
  58.  
  59. local should_append_config = true
  60. for i, v in pairs(i3_config:read("a"):split("\n")) do
  61. if v:find("include") and v:find("floating_windows%.conf") then
  62. should_append_config = false
  63. end
  64. end
  65.  
  66. if should_append_config then
  67. os.execute('echo "" >> ~/.config/i3/config')
  68. os.execute('echo "# autogenerated" >> ~/.config/i3/config')
  69. os.execute('echo "include ~/.config/i3/floating_windows.conf" >> ~/.config/i3/config')
  70.  
  71. print("... appended i3 config")
  72. end
  73.  
  74. os.execute(
  75. string.format('echo "for_window [class=\\"%s\\"] floating enable" >> ~/.config/i3/floating_windows.conf', wm_class)
  76. )
  77. floating_windows:close()
  78.  
  79. print("... registered floating window:", wm_class)
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement