summaryrefslogtreecommitdiff
path: root/.i3/scripts
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2013-06-07 12:51:19 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2013-06-07 12:51:20 +0200
commitc186d79b39abe91439542a822bdb48ad39e45a0d (patch)
tree012746d559dd3efd00cf7e8d8ba688b16fa26061 /.i3/scripts
parentc95c38a276f01c8cb5dfdb5ccaacb29e2afd69a4 (diff)
downloaddotfiles-c186d79b39abe91439542a822bdb48ad39e45a0d.tar.gz
dotfiles-c186d79b39abe91439542a822bdb48ad39e45a0d.tar.bz2
dotfiles-c186d79b39abe91439542a822bdb48ad39e45a0d.zip
i3: Overhaul workspaces.py
Diffstat (limited to '')
-rwxr-xr-x.i3/scripts/workspaces.py46
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)
pan>Update for new URL.Jason A. Donenfeld3-3/+3 2014-05-14Bump version1.6.2Jason A. Donenfeld1-1/+1 2014-05-14Don't define tmpdir on git init.Jason A. Donenfeld1-4/+3 2014-05-14Disable secmem warning when discovering keysmilki2-2/+2 2014-05-10edit: Quote editor so tests work in spaced directories.Jason A. Donenfeld1-1/+1 2014-05-10reencryption: Properly escape input to sedJason A. Donenfeld1-1/+1 2014-05-10git: use secure tmp directoryJason A. Donenfeld1-4/+11 2014-05-10configure git to decrypt gpg files automaticallySamuel Le Thiec1-0/+5 2014-05-08completion: add new generate flagsJason A. Donenfeld3-2/+7 2014-05-08inplace: mutually exclusive with forceJason A. Donenfeld2-3/+3 2014-05-08usage: tab to spacesJason A. Donenfeld1-1/+1 2014-05-08generate: use nice ansi colors instead.Jason A. Donenfeld1-3/+2 2014-05-08zsh: posix compatible sed fix for zsh-completionJason A. Donenfeld1-1/+1 2014-05-07Implement interactive init functionSvend Sorensen1-0/+8 2014-05-07Implement interactive rename functionSvend Sorensen1-0/+7 2014-05-07Reorder interactive function to match order of helper functionsSvend Sorensen1-13/+13 2014-05-07Make edit helper function name consistent with other helpersSvend Sorensen1-1/+1 2014-05-07Factor out password completing-read functionSvend Sorensen1-4/+8 2014-05-07Add dash to Package-RequiresSvend Sorensen1-1/+1 2014-05-06Force sane sort order.Jason A. Donenfeld1-2/+2 2014-05-06generate: add --in-place optionJason A. Donenfeld4-9/+33