Created
November 7, 2019 15:39
-
-
Save Nama/42eec6813eea7a25741992a394cf1202 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import i3ipc | |
import sys | |
import pickle | |
PATH = os.path.expanduser("~/.config/i3/workspace_mapping") | |
def showHelp(): | |
print(sys.argv[0] + " [save|restore]") | |
if __name__ == '__main__': | |
i3 = i3ipc.Connection() | |
if len(sys.argv) < 2: | |
showHelp() | |
sys.exit(1) | |
if sys.argv[1] == 'save': | |
pickle.dump(i3.get_workspaces(), open(PATH, "wb")) | |
elif sys.argv[1] == 'restore': | |
try: | |
workspace_mapping = pickle.load(open(PATH, "rb")) | |
except Exception: | |
print("Can't find existing mappings...") | |
sys.exit(1) | |
for workspace in workspace_mapping: | |
i3.command('workspace %s' % workspace.name) | |
i3.command('move workspace to output %s' % workspace.output) | |
for workspace in filter(lambda w: w.visible, workspace_mapping): | |
i3.command('workspace %s' % workspace.name) | |
else: | |
showHelp() | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment