summaryrefslogtreecommitdiff
path: root/.i3/scripts
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2013-06-14 19:08:21 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2013-06-14 19:08:22 +0200
commit6f95bc805e35a209a058b6f096b42b5447073632 (patch)
tree44a877472ea675f0b6f9426cd6dc9f9a31e58224 /.i3/scripts
parent3b7022534099866a6846745cd720a41c5335afe1 (diff)
downloaddotfiles-6f95bc805e35a209a058b6f096b42b5447073632.tar.gz
dotfiles-6f95bc805e35a209a058b6f096b42b5447073632.tar.bz2
dotfiles-6f95bc805e35a209a058b6f096b42b5447073632.zip
i3: New 'open new workspace with a terminal on'
Diffstat (limited to '.i3/scripts')
-rwxr-xr-x.i3/scripts/workspaces.py40
1 files changed, 27 insertions, 13 deletions
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)