From 6f95bc805e35a209a058b6f096b42b5447073632 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Fri, 14 Jun 2013 19:08:21 +0200 Subject: i3: New 'open new workspace with a terminal on' --- .i3/scripts/workspaces.py | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to '.i3/scripts') diff --git a/.i3/scripts/workspaces.py b/.i3/scripts/workspaces.py index 498587b..752205a 100755 --- a/.i3/scripts/workspaces.py +++ b/.i3/scripts/workspaces.py @@ -8,7 +8,7 @@ # import sys -from os.path import realpath, dirname, join +from os.path import realpath, dirname, join, basename cwd = realpath(dirname(__file__)) sys.path.insert(1, join(cwd, "libs")) @@ -19,14 +19,22 @@ from functools import partial DEFAULT = "switch" +def nag(msg, **kwargs): + sh.i3_nagbar(m = "%s: %s" % (basename(sys.argv[0]), msg), **kwargs) + switch = i3.workspace move = partial(i3.move, "container to workspace") -def new_ws(cmd): +def new_ws(cmd, args): """Create a new workspace by using the first free number > 0.""" nums = (w["num"] for w in i3.get_workspaces()) nums = filter(lambda n: n is not None and n >= 0, nums) + try: + exe = args[args.index("--exec")+1] + except IndexError, ValueError: + exe = None + for i,n in enumerate(sorted(nums)): if i != n: cmd(str(i)) @@ -34,7 +42,13 @@ def new_ws(cmd): else: cmd(str(i+1)) -def to_ws(cmd, prompt): + if exe: + try: + sh.Command(exe)() + except sh.CommandNotFound: + nag("Command '%s' not found!" % exe) + +def to_ws(cmd, prompt, args): """Use `dmenu` to switch or move to a workspace.""" ws = sorted(w["name"] for w in i3.get_workspaces()) @@ -46,11 +60,11 @@ def to_ws(cmd, prompt): if sel is not None: cmd(sel) -def rename(keep = False): +def rename(args): cur_ws = i3.filter(i3.get_workspaces(), focused = True)[0] input = partial(sh.i3_input, P = "Rename workspace: ") - if keep and cur_ws["num"]: + if "--keep-num" in args and cur_ws["num"]: input(F = ('rename workspace to "%d: %%s"' % cur_ws["num"])) else: input(F = 'rename workspace to "%s"') @@ -58,22 +72,22 @@ def rename(keep = False): if __name__ == "__main__": try: arg = sys.argv[1] + args = sys.argv[1:] except IndexError: arg = DEFAULT + args = [] if arg == "switch": - to_ws(switch, "Switch to:") + to_ws(switch, "Switch to:", args) elif arg == "move": - to_ws(move, "Move to:") + to_ws(move, "Move to:", args) elif arg == "new": - new_ws(switch) + new_ws(switch, args) elif arg == "move_new": - new_ws(move) + new_ws(move, args) elif arg == "rename": - rename(False) - elif arg == "rename_num": - rename(True) + rename(args) else: - print("Unknown arg: %s" % arg) + nag("Unknown arg: %s" % arg) sys.exit(1) -- cgit v1.2.3-54-g00ecf