From b1e88f0f934a6854eed7b9ba0ef3ba80fe236c4f Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 17 Jul 2021 13:05:00 +0200 Subject: [PATCH] bin: add i3-tabbed Stolen from https://github.com/aduros/dotfiles/blob/master/home/bin/i3-tabbed. --- bin/i3-tabbed | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 bin/i3-tabbed diff --git a/bin/i3-tabbed b/bin/i3-tabbed new file mode 100755 index 0000000..ad35050 --- /dev/null +++ b/bin/i3-tabbed @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# +# Splits the current terminal into a tab layout, runs a command, then restores the original layout. +# Handy for opening images and videos "inside" a terminal. +# +# This effect is similar to dwm's window swallowing patch: https://www.youtube.com/watch?v=92uo5OBOKfY +# +# To be super minimal, configure i3 to use a 0px font size to hide the tab title bars. With the +# unfortunate caveat that this will cause i3 error messages to become unreadable. + +from i3ipc import Connection +import subprocess +import sys + +if len(sys.argv) < 2: + print("Usage: %s " % sys.argv[0]) + sys.exit(1) + +i3 = Connection() +orig = i3.get_tree().find_focused() + +# If the layout was already tabbed or stacked, don't do anything +layout = orig.parent.layout +if layout == "splith": + orig.command("split v") + orig.command("layout tabbed") +elif layout == "splitv": + orig.command("split h") + orig.command("layout tabbed") + +try: + # Run the given command + code = subprocess.run(sys.argv[1:]).returncode + +finally: + # Unsplit the container if it was previously split to restore the old layout + if layout == "splith": + orig.command("layout default") + orig.command("move left") + elif layout == "splitv": + orig.command("layout default") + orig.command("move up") + +# Pass along the command's return code +sys.exit(code)