From 6f95bc805e35a209a058b6f096b42b5447073632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Fri, 14 Jun 2013 19:08:21 +0200 Subject: i3: New 'open new workspace with a terminal on' --- .i3/config | 6 ++++-- .i3/scripts/workspaces.py | 40 +++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 15 deletions(-) (limited to '.i3') diff --git a/.i3/config b/.i3/config index 3e127eb..8e24153 100644 --- a/.i3/config +++ b/.i3/config @@ -10,6 +10,7 @@ set $alt Mod1 set $dir $HOME/.i3 set $script $HOME/.i3/scripts set $nsi --no-startup-id +set $term urxvtc # General Settings «1 ################################################ @@ -154,11 +155,12 @@ bindsym $mod+Shift+g exec $nsi $script/workspaces.py move # rename «3 bindsym $mod+Shift+r exec $nsi $script/workspaces.py rename -bindsym $mod+r exec $nsi $script/workspaces.py rename_num +bindsym $mod+r exec $nsi $script/workspaces.py rename --keep-num # new temp workspace «3 bindsym $mod+n exec $nsi $script/workspaces.py new bindsym $mod+Shift+n exec $nsi $script/workspaces.py move_new +bindsym $mod+Shift+Return exec $nsi $script/workspaces.py new --exec $term # Resizing «2 ############# @@ -187,7 +189,7 @@ bindsym $mod+grave mode "resize" # Start Programs «2 ################### # Terminal -bindsym $mod+Return exec urxvtc +bindsym $mod+Return exec $term # start dmenu (a program launcher) bindsym $mod+space exec dmenu_run -b 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