-
Notifications
You must be signed in to change notification settings - Fork 1
Add distrobox container integration for tmux, zellij, and fish #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
43e03de
Add tmux statusbar auto-hide and mouse bindings
tyvsmith fc12f51
Add distrobox container integration for tmux, zellij, and fish
tyvsmith 7a0ee04
Fix zellij container picker: multi-action fzf with close_on_exit
tyvsmith 4a676eb
Refine zellij container picker actions
tyvsmith e23f8fe
Replace current-pane text injection with floating pane in zellij picker
tyvsmith 402e2ad
Unify tmux and zellij container picker into single multi-action UI
tyvsmith 4e55120
Convert container-fzf from fish function to POSIX bash script
tyvsmith 72552ee
Converge container picker keybinds between tmux and zellij
tyvsmith 2b98837
Drop alt-f floating action from zellij container picker
tyvsmith bf1fd5e
Fix PR review issues: grep+set -e, command injection, stale bindings
tyvsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/usr/bin/env bash | ||
| # container-pick-send.sh — tmux popup wrapper for container-fzf | ||
| # Runs the multi-action container picker inside a tmux popup. | ||
| # The popup provides the TTY that fzf needs. | ||
|
|
||
| exec container-fzf --tmux |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/usr/bin/env bash | ||
| # container-split.sh — Container-aware tmux split | ||
| # If the current pane is inside a distrobox container, the new split | ||
| # automatically enters the same container. Otherwise, opens a normal shell. | ||
| # | ||
| # Usage: container-split.sh [-h|-v] | ||
| # -h horizontal split (side by side) | ||
| # -v vertical split (top/bottom) | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SPLIT_DIR="${1:--h}" | ||
|
|
||
| # Get the active pane's PID, then walk its child processes to find CONTAINER_ID | ||
| PANE_PID=$(tmux display-message -p '#{pane_pid}') | ||
| CONTAINER_ID="" | ||
|
|
||
| # Check the pane's environment for CONTAINER_ID | ||
| # Walk the process tree to find a shell that has CONTAINER_ID set | ||
| if [ -n "$PANE_PID" ]; then | ||
| # Try to read CONTAINER_ID from any child process of the pane | ||
| for pid in $(pgrep -P "$PANE_PID" 2>/dev/null || true) $PANE_PID; do | ||
| if [ -r "/proc/$pid/environ" ]; then | ||
| cid=$(tr '\0' '\n' < "/proc/$pid/environ" 2>/dev/null | sed -n 's/^CONTAINER_ID=//p' | head -1) | ||
| if [ -n "$cid" ]; then | ||
| CONTAINER_ID="$cid" | ||
| break | ||
| fi | ||
| fi | ||
| done | ||
| fi | ||
|
|
||
| if [ -n "$CONTAINER_ID" ]; then | ||
| # Sanitize: only allow alphanumeric, dash, underscore, dot | ||
| if ! [[ "$CONTAINER_ID" =~ ^[A-Za-z0-9._-]+$ ]]; then | ||
| echo "container-split.sh: invalid CONTAINER_ID: $CONTAINER_ID" >&2 | ||
| exit 1 | ||
| fi | ||
| # Inside a container — new split enters the same container | ||
| tmux split-window "$SPLIT_DIR" -c "#{pane_current_path}" -- distrobox enter "$CONTAINER_ID" | ||
| else | ||
| # On host — normal split | ||
| tmux split-window "$SPLIT_DIR" -c "#{pane_current_path}" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/usr/bin/env bash | ||
| # container-status.sh — Show the container name for the active tmux pane | ||
| # Returns the CONTAINER_ID if the active pane is inside a distrobox/toolbox, | ||
| # or empty string if on the host. Used in tmux status-right. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| PANE_PID=$(tmux display-message -p '#{pane_pid}' 2>/dev/null) | ||
| [ -z "$PANE_PID" ] && exit 0 | ||
|
|
||
| # Walk the pane's process tree looking for CONTAINER_ID | ||
| for pid in $(pgrep -P "$PANE_PID" 2>/dev/null || true) $PANE_PID; do | ||
| if [ -r "/proc/$pid/environ" ]; then | ||
| cid=$(tr '\0' '\n' < "/proc/$pid/environ" 2>/dev/null | sed -n 's/^CONTAINER_ID=//p' | head -1) | ||
| if [ -n "$cid" ]; then | ||
| echo " $cid" | ||
| exit 0 | ||
| fi | ||
| fi | ||
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Container development layout for zellij | ||
| // Usage: zellij --layout container | ||
| // | ||
| // Opens a host tab and a container picker tab. | ||
| // To create a named session using this layout, use: | ||
| // zellij --layout container --session my-project | ||
|
|
||
| layout { | ||
| default_tab_template { | ||
| pane size=1 borderless=true { | ||
| plugin location="compact-bar" | ||
| } | ||
| children | ||
| } | ||
|
|
||
| tab name="host" focus=true { | ||
| pane name="shell" | ||
| } | ||
|
|
||
| tab name="container" { | ||
| pane name="picker" command="fish" { | ||
| args "-c" "container-fzf" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| #!/usr/bin/env bash | ||
| # container-fzf: Interactive container picker using fzf | ||
| # Lists distrobox containers and enters the selected one. | ||
| # Works from any shell. Called standalone or by tmux/zellij integrations. | ||
| # | ||
| # Flags: | ||
| # --tmux tmux mode: enter=new window, alt-s=split, alt-f=N/A | ||
| # --zellij zellij mode: enter=new tab, alt-s=split | ||
| # --print-only Print the enter command instead of executing it | ||
| # --running-only Only show running containers | ||
| # --header TEXT Override the fzf header text | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # ── Parse flags ────────────────────────────────────────────────────── | ||
| mode="" | ||
| print_only=0 | ||
| running_only=0 | ||
| custom_header="" | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --tmux) mode="tmux"; shift ;; | ||
| --zellij) mode="zellij"; shift ;; | ||
| --print-only) print_only=1; shift ;; | ||
| --running-only) running_only=1; shift ;; | ||
| --header) custom_header="$2"; shift 2 ;; | ||
| *) echo "container-fzf: unknown flag: $1" >&2; exit 1 ;; | ||
| esac | ||
| done | ||
|
|
||
| # ── Guards ─────────────────────────────────────────────────────────── | ||
| if ! command -v distrobox >/dev/null 2>&1; then | ||
| echo "container-fzf: distrobox not found" >&2 | ||
| exit 1 | ||
| fi | ||
| if ! command -v fzf >/dev/null 2>&1; then | ||
| echo "container-fzf: fzf not found" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # ── Header text ────────────────────────────────────────────────────── | ||
| if [[ -n "$custom_header" ]]; then | ||
| fzf_header="$custom_header" | ||
| elif [[ "$mode" == "tmux" ]]; then | ||
| fzf_header="enter: new window | alt-s: split" | ||
| elif [[ "$mode" == "zellij" ]]; then | ||
| fzf_header="enter: new tab | alt-s: split" | ||
| else | ||
| fzf_header="Select container" | ||
| fi | ||
|
|
||
| # ── Get container list ─────────────────────────────────────────────── | ||
| db_output=$(distrobox list --no-color 2>/dev/null | tail -n +2) | ||
|
|
||
| if [[ -z "$db_output" ]]; then | ||
| echo "container-fzf: no distrobox containers found" >&2 | ||
| echo "Create one with: distrobox create --name <name> --image <image>" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Filter to running only if requested | ||
| if [[ "$running_only" -eq 1 ]]; then | ||
| db_output=$(echo "$db_output" | grep 'Up' || true) | ||
| if [[ -z "$db_output" ]]; then | ||
| echo "container-fzf: no running containers" >&2 | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| # ── Build fzf command ──────────────────────────────────────────────── | ||
| fzf_args=( | ||
| --header "$fzf_header" | ||
| --preview 'sh -c '\''name=$(echo "$1" | awk -F"|" "{print \$2}" | xargs); echo "$1"; echo "---"; podman inspect --format "Image: {{.Config.Image}}\nCreated: {{.Created}}\nState: {{.State.Status}}" "$name" 2>/dev/null || echo "Container not running - will start on enter"'\'' -- {}' | ||
| --prompt "container> " | ||
| --layout reverse | ||
| --border rounded | ||
| --ansi | ||
| ) | ||
|
|
||
| # Multi-action modes use --expect to capture which key was pressed | ||
| if [[ "$mode" == "tmux" ]]; then | ||
| fzf_args+=(--expect "alt-s") | ||
| elif [[ "$mode" == "zellij" ]]; then | ||
| fzf_args+=(--expect "alt-s") | ||
| fi | ||
|
|
||
| # ── Run fzf ────────────────────────────────────────────────────────── | ||
| fzf_output=$(echo "$db_output" | fzf "${fzf_args[@]}") || exit 0 | ||
|
|
||
| if [[ -z "$fzf_output" ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| # With --expect, first line is the key pressed, second is the selection | ||
| # Without --expect, the only line is the selection | ||
| key="" | ||
| selected="" | ||
| if [[ -n "$mode" ]]; then | ||
| key=$(echo "$fzf_output" | head -1) | ||
| selected=$(echo "$fzf_output" | tail -1) | ||
| else | ||
| selected="$fzf_output" | ||
| fi | ||
|
|
||
| if [[ -z "$selected" ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Extract container name (second column, pipe-delimited) | ||
| container_name=$(echo "$selected" | awk -F'|' '{print $2}' | xargs) | ||
|
|
||
| if [[ -z "$container_name" ]]; then | ||
| echo "container-fzf: could not parse container name" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # ── --print-only ───────────────────────────────────────────────────── | ||
| if [[ "$print_only" -eq 1 ]]; then | ||
| echo "distrobox enter $container_name" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # ── tmux multi-action mode ─────────────────────────────────────────── | ||
| # All actions run distrobox as the pane/window command directly. | ||
| # The popup closes automatically when this script exits. | ||
| if [[ "$mode" == "tmux" ]]; then | ||
| case "$key" in | ||
| alt-s) tmux split-window -v "distrobox enter $container_name" ;; | ||
| *) tmux new-window -n "$container_name" "distrobox enter $container_name" ;; | ||
| esac | ||
| exit 0 | ||
| fi | ||
|
|
||
| # ── zellij multi-action mode ──────────────────────────────────────── | ||
| # Picker pane has close_on_exit=true, so it auto-closes when script exits. | ||
| # All actions launch distrobox as the pane's command directly. | ||
| if [[ "$mode" == "zellij" ]]; then | ||
| case "$key" in | ||
| alt-s) | ||
| # Tiled split running distrobox directly | ||
| zellij action toggle-floating-panes | ||
| zellij action new-pane -d down --name "$container_name" -- distrobox enter "$container_name" | ||
| ;; | ||
| *) | ||
| # New tab via temp layout with UI chrome (Enter key) | ||
| layout_file=$(mktemp /tmp/zellij-container-XXXXXX.kdl) | ||
| cat > "$layout_file" << LAYOUT | ||
| layout { | ||
| pane size=1 borderless=true { | ||
| plugin location="compact-bar" | ||
| } | ||
| pane command="distrobox" { | ||
| args "enter" "$container_name" | ||
| name "$container_name" | ||
| } | ||
| pane size=1 borderless=true { | ||
| plugin location="status-bar" | ||
| } | ||
| } | ||
| LAYOUT | ||
| zellij action new-tab --layout "$layout_file" --name "$container_name" | ||
| rm -f "$layout_file" | ||
| ;; | ||
| esac | ||
| exit 0 | ||
| fi | ||
|
|
||
| # ── Default (no multiplexer flag) ──────────────────────────────────── | ||
| # Enter the container in the current shell | ||
| exec distrobox enter "$container_name" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This re-binds
prefix+h/prefix+vto run the container-aware split scripts, but the config still contains earlier bindings forbind h split-window .../bind v split-window ...(lines 22–23) which will now be overridden. Consider removing or updating the earlier bindings to avoid confusing duplicates and make it clear that these keys are intentionally repurposed.