You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Add bash completion for tmux session-alias commands
✨ Enhancement🕐 Less than 10 minutes
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'.
_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.
+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).
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
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
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.
Add bash autocomplete support for the
ta,tad, andtkssaliases in the tmux plugin. This allows users to press tab to autocomplete active tmux session names when using these aliases.