Dotfiles for different machines on different branches.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
925 B

  1. #!/usr/bin/env python3
  2. import i3ipc
  3. import subprocess
  4. import re
  5. i3 = i3ipc.Connection()
  6. def get_scratchpad_windows():
  7. scratchpad_containers = i3.get_tree().scratchpad().descendants()
  8. return filter(lambda c: c.type == 'con' and c.name, scratchpad_containers)
  9. def dmenu_choose(options):
  10. """ Show a dmenu to choose a string item from a list of *options*. """
  11. dmenu_process = subprocess.Popen(["dmenu", "-l", "10"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  12. stdoutdata, _ = dmenu_process.communicate("\n".join(options).encode())
  13. return stdoutdata.decode('utf-8')
  14. def main():
  15. scratchpad_windows = get_scratchpad_windows()
  16. window_titles = [w.name for w in scratchpad_windows]
  17. if window_titles:
  18. window_to_restore = re.escape(dmenu_choose(window_titles).strip())
  19. i3.command('[title="{}"] scratchpad show'.format(window_to_restore))
  20. if __name__ == '__main__':
  21. main()