Guest User

run_or_raise

a guest
May 19th, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  1. function run_or_raise(cmd, properties)
  2. local clients = client.get()
  3. local focused = awful.client.next(0)
  4. local findex = 0
  5. local matched_clients = {}
  6. local n = 0
  7. for i, c in pairs(clients) do
  8. --make an array of matched clients
  9. if match(properties, c) then
  10. n = n + 1
  11. matched_clients[n] = c
  12. if c == focused then
  13. findex = n
  14. end
  15. end
  16. end
  17. if n > 0 then
  18. local c = matched_clients[1]
  19. -- if the focused window matched switch focus to next in list
  20. if 0 < findex and findex < n then
  21. c = matched_clients[findex+1]
  22. end
  23. local ctags = c:tags()
  24. if #ctags == 0 then
  25. -- ctags is empty, show client on current tag
  26. local curtag = awful.tag.selected()
  27. awful.client.movetotag(curtag, c)
  28. else
  29. -- Otherwise, pop to first tag client is visible on
  30. awful.tag.viewonly(ctags[1])
  31. end
  32. -- And then focus the client
  33. client.focus = c
  34. c:raise()
  35. return
  36. end
  37. awful.util.spawn(cmd)
  38. end
  39.  
  40. -- Returns true if all pairs in table1 are present in table2
  41. function match (table1, table2)
  42. for k, v in pairs(table1) do
  43. if table2[k] ~= v and not table2[k]:find(v) then
  44. return false
  45. end
  46. end
  47. return true
  48. end
Advertisement
Add Comment
Please, Sign In to add comment