Skip to content

Instantly share code, notes, and snippets.

@ferdinandyb
Last active June 19, 2020 18:02
Show Gist options
  • Save ferdinandyb/6fee493184b358653dd89cd2f27b0070 to your computer and use it in GitHub Desktop.
Save ferdinandyb/6fee493184b358653dd89cd2f27b0070 to your computer and use it in GitHub Desktop.
next window script idea
#!/usr/bin/env python3
import i3ipc
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description = "Find the next non-opened workspace and go there.")
parser.add_argument('--startnum',type=int,default = 1,
help="Set smallest workspace number, usually change to 0 if anything.")
group = parser.add_mutually_exclusive_group()
group.add_argument("-mv","--move-window",action="store_true",
help="Instead of going to next non-opened workspace, move current window there.")
group.add_argument("-mvf","--move-window-and-follow",action="store_true",
help="Move current window to next non-opened workspace and follow.")
args = parser.parse_args()
startnum = args.startnum
i3 = i3ipc.Connection()
workspaces = i3.get_workspaces()
nums = {w.num for w in workspaces}
font = workspaces[0].name.split("'")[1]
s_ = {x for x in range(args.startnum,args.startnum + 20)}
targetnum = min(s_ - nums)
targetstring = "{0}:<span font_desc='{1}'> {0} </span>".format(targetnum,font)
if args.move_window or args.move_window_and_follow:
i3.command("move container workspace " + targetstring)
if not args.move_window:
i3.command("workspace number " + targetstring)
@ferdinandyb
Copy link
Author

Updated to call by name to make it look the same as when opening with a keybind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment