Skip to content

Instantly share code, notes, and snippets.

@Nama
Created November 7, 2019 15:39
Show Gist options
  • Save Nama/42eec6813eea7a25741992a394cf1202 to your computer and use it in GitHub Desktop.
Save Nama/42eec6813eea7a25741992a394cf1202 to your computer and use it in GitHub Desktop.
#!/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