1
0
mirror of https://github.com/tiyn/dotfiles.git synced 2025-03-18 18:07:45 +01:00
dotfiles/.local/bin/i3cmds/i3-scratchpad-dmenu.py
2019-10-13 10:49:45 +02:00

28 lines
925 B
Python

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