#!/usr/bin/env bash set -euo pipefail # Replace the current zellij tab by opening a layout in a new tab # and closing the original tab. # # Usage: # zellij-replace-tab-layout.sh # uses "dev" # zellij-replace-tab-layout.sh dev # zellij-replace-tab-layout.sh my-layout layout="${1:-dev}" case "${layout}" in -h|--help) cat <<'EOF' zellij-replace-tab-layout.sh Replace the current zellij tab with a new tab created from a layout. This avoids `zellij action override-layout` glitches. Usage: zellij-replace-tab-layout.sh [layout] Examples: zellij-replace-tab-layout.sh zellij-replace-tab-layout.sh dev zellij-replace-tab-layout.sh dotfiles EOF exit 0 ;; esac if ! command -v zellij >/dev/null 2>&1; then echo "zellij not found in PATH" >&2 exit 1 fi if [ -z "${ZELLIJ:-}" ]; then echo "Not inside a zellij session (ZELLIJ is not set)" >&2 exit 1 fi current_tab_id="$(zellij action current-tab-info | awk '/^id:/ { print $2 }')" if [ -z "$current_tab_id" ]; then echo "Failed to detect current tab id" >&2 exit 1 fi zellij action new-tab --layout "$layout" >/dev/null zellij action close-tab --tab-id "$current_tab_id"