Skip to content

feat(tmux): add bash completion for session aliases#768

Open
senderic wants to merge 2 commits into
ohmybash:masterfrom
senderic:feat/tmux-completion
Open

feat(tmux): add bash completion for session aliases#768
senderic wants to merge 2 commits into
ohmybash:masterfrom
senderic:feat/tmux-completion

Conversation

@senderic

Copy link
Copy Markdown

Add bash autocomplete support for the ta, tad, and tkss aliases in the tmux plugin. This allows users to press tab to autocomplete active tmux session names when using these aliases.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Add bash completion for tmux session-alias commands

✨ Enhancement 🕐 Less than 10 minutes

Grey Divider

AI Description

• Add bash tab-completion for ta, tad, and tkss tmux aliases
• Complete against active tmux session names from tmux list-sessions
• Gracefully handle missing tmux server by suppressing list errors
Diagram

graph TD
U["User presses Tab"] --> B["bash completion"] --> F["_omb_tmux_alias_sessions()"] --> T["tmux list-sessions"] --> R["COMPREPLY candidates"]
subgraph Legend
  direction LR
  _u["User action"] ~~~ _fn["Shell function"] ~~~ _ext{{"External command"}}
end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Reuse/share a generic tmux-session completion helper
  • ➕ Avoids duplication if other tmux commands/aliases need session completion later
  • ➕ Centralizes tmux error-handling and filtering behavior
  • ➖ Slight upfront refactor for a small change
  • ➖ May be premature if no other completions are planned
2. Conditionally register completion only when tmux exists
  • ➕ Avoids defining completion for users without tmux installed
  • ➕ Reduces unnecessary completion overhead in minimal environments
  • ➖ Adds branching and environment checks to plugin init
  • ➖ Current approach is already safe due to stderr suppression

Recommendation: The current approach is appropriate for the scope: a small, self-contained completion function using tmux list-sessions and compgen. If more tmux alias completions are expected, consider extracting a shared session-completion helper to keep behavior consistent across aliases.

Files changed (1) +9 / -0

Enhancement (1) +9 / -0
tmux.plugin.bashAdd programmable completion for tmux session aliases +9/-0

Add programmable completion for tmux session aliases

• Introduces a bash completion function that lists current tmux sessions and uses 'compgen' to match the active word. Registers this function as the completion handler for 'ta', 'tad', and 'tkss'.

plugins/tmux/tmux.plugin.bash

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jul 15, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Unsafe completion splitting ✓ Resolved 🐞 Bug ≡ Correctness
Description
_omb_tmux_alias_sessions builds COMPREPLY via an unquoted command substitution, so completion
candidates are subject to shell word-splitting and pathname expansion (globbing), which can corrupt
tmux session-name suggestions. In particular, session names containing characters like * or [
may expand to matching filenames in the current directory, and names with spaces can be split into
multiple candidates.
Code

plugins/tmux/tmux.plugin.bash[R51-55]

+function _omb_tmux_alias_sessions() {
+  local cur="${COMP_WORDS[COMP_CWORD]}"
+  local sessions=$(tmux list-sessions -F "#S" 2>/dev/null)
+  COMPREPLY=( $(compgen -W "${sessions}" -- "${cur}") )
+}
Evidence
The new completion assigns COMPREPLY using unquoted command substitution, which is subject to word
splitting and glob expansion. The codebase already contains and uses a helper designed to safely
split command output into arrays for completions by setting IFS=$'\n' and set -f (disable
globbing).

plugins/tmux/tmux.plugin.bash[50-57]
lib/utils.sh[450-456]
lib/cli.bash[63-66]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The completion function populates `COMPREPLY` using `COMPREPLY=( $(...) )`, which applies word-splitting and pathname expansion to `compgen` output. This can produce incorrect completion candidates (e.g., file names) or split multi-word session names.
## Issue Context
The repo already provides `_omb_util_split_lines`, which disables globbing (`set -f`) and splits safely by newline for completion arrays.
## Fix Focus Areas
- plugins/tmux/tmux.plugin.bash[50-57]
## Suggested fix approach
1. Read tmux sessions into an array with `_omb_util_split_lines`.
2. Build `COMPREPLY` without unquoted command substitution.
Example implementation (one option):

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment thread plugins/tmux/tmux.plugin.bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant