#!/usr/bin/python3

import sys
import i3

import utils

names = utils.get_workspace_names()
if len(sys.argv) == 1:
    choice = utils.run_dmenu(names, "-p", "moveto: ")
    if not choice in names:
        choice = utils.insert_new_workspace(names, choice)
else:
    index = int(sys.argv[1])
    ind = (index - 1 + len(names)) % (len(names))
    if index > len(names):
        choice = str(index)+": "
    else:
        choice = names[ind]
i3.command("move workspace", choice)
utils.sort_workspaces()
