diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2013-06-07 12:51:19 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2013-06-07 12:51:20 +0200 |
commit | c186d79b39abe91439542a822bdb48ad39e45a0d (patch) | |
tree | 012746d559dd3efd00cf7e8d8ba688b16fa26061 /.i3/scripts | |
parent | c95c38a276f01c8cb5dfdb5ccaacb29e2afd69a4 (diff) | |
download | dotfiles-c186d79b39abe91439542a822bdb48ad39e45a0d.tar.gz dotfiles-c186d79b39abe91439542a822bdb48ad39e45a0d.tar.bz2 dotfiles-c186d79b39abe91439542a822bdb48ad39e45a0d.zip |
i3: Overhaul workspaces.py
Diffstat (limited to '')
-rwxr-xr-x | .i3/scripts/workspaces.py | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/.i3/scripts/workspaces.py b/.i3/scripts/workspaces.py index 4c0ec87..44de01f 100755 --- a/.i3/scripts/workspaces.py +++ b/.i3/scripts/workspaces.py @@ -15,46 +15,36 @@ sys.path.insert(1, join(cwd, "libs")) import i3 import sh +from functools import partial DEFAULT = "switch" -def ws_dmenu(**kw): - """Call `dmenu` with the names of the current workspaces. - Arguments are directly passed to `dmenu`. +switch = i3.workspace +move = partial(i3.move, "container to workspace") - Returns the stripped output of dmenu or `None`.""" - - ws = sorted(w["name"] for w in i3.get_workspaces()) - - try: - return sh.dmenu("-b", _in = "\n".join(ws), **kw).strip() or None - except sh.ErrorReturnCode: - return None - -def new_ws(): +def new_ws(cmd): """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) for i,n in enumerate(sorted(nums)): if i != n: - i3.workspace(str(i)) + cmd(str(i)) break else: - i3.workspace(str(i+1)) + cmd(str(i+1)) +def to_ws(cmd, prompt): + """Use `dmenu` to switch or move to a workspace.""" + ws = sorted(w["name"] for w in i3.get_workspaces()) -def switch_ws(): - """Use `dmenu` to switch to a workspace.""" - sel = ws_dmenu(p="Switch to:") - if sel is not None: - i3.workspace(sel) + try: + sel = (sh.dmenu("-b", _in = "\n".join(ws), p=prompt).strip() or None) + except sh.ErrorReturnCode: + sel = None -def move_to_ws(): - """Use `dmenu` to move the current container to a workspace.""" - sel = ws_dmenu(p="Move to:") if sel is not None: - i3.move("container to workspace", sel) + cmd(sel) if __name__ == "__main__": try: @@ -63,11 +53,13 @@ if __name__ == "__main__": arg = DEFAULT if arg == "switch": - switch_ws() + to_ws(switch, "Switch to:") elif arg == "move": - move_to_ws() + to_ws(move, "Move to:") elif arg == "new": - new_ws() + new_ws(switch) + elif arg == "move_new": + new_ws(move) else: print("Unknown arg: %s" % arg) sys.exit(1) |