Don't require tmux server to be running for completion to work.

pull/145/head
Von Welch 2012-06-30 16:47:13 -04:00
parent 84fac4f680
commit e2e63c9662
1 changed files with 89 additions and 6 deletions

View File

@ -5,6 +5,90 @@
# Usage: Put "source bash_completion_tmux.sh" into your .bashrc # Usage: Put "source bash_completion_tmux.sh" into your .bashrc
# Based upon the example at http://paste-it.appspot.com/Pj4mLycDE # Based upon the example at http://paste-it.appspot.com/Pj4mLycDE
_tmux_cmds=" \
attach-session \
bind-key \
break-pane \
capture-pane \
choose-client \
choose-session \
choose-window \
clear-history \
clock-mode \
command-prompt \
confirm-before \
copy-buffer \
copy-mode \
delete-buffer \
detach-client \
display-message \
display-panes \
down-pane \
find-window \
has-session \
if-shell \
join-pane \
kill-pane \
kill-server \
kill-session \
kill-window \
last-window \
link-window \
list-buffers \
list-clients \
list-commands \
list-keys \
list-panes \
list-sessions \
list-windows \
load-buffer \
lock-client \
lock-server \
lock-session \
move-window \
new-session \
new-window \
next-layout \
next-window \
paste-buffer \
pipe-pane \
previous-layout \
previous-window \
refresh-client \
rename-session \
rename-window \
resize-pane \
respawn-window \
rotate-window \
run-shell \
save-buffer \
select-layout \
select-pane \
select-prompt \
select-window \
send-keys \
send-prefix \
server-info \
set-buffer \
set-environment \
set-option \
set-window-option \
show-buffer \
show-environment \
show-messages \
show-options \
show-window-options \
source-file \
split-window \
start-server \
suspend-client \
swap-pane \
swap-window \
switch-client \
unbind-key \
unlink-window \
up-pane"
_tmux_expand () _tmux_expand ()
{ {
[ "$cur" != "${cur%\\}" ] && cur="$cur"'\'; [ "$cur" != "${cur%\\}" ] && cur="$cur"'\';
@ -34,12 +118,12 @@ _tmux_filedir ()
function _tmux_complete_client() { function _tmux_complete_client() {
local IFS=$'\n' local IFS=$'\n'
local cur="${1}" local cur="${1}"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-clients | cut -f 1 -d ':')" -- "${cur}") ) COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-clients 2>/dev/null | cut -f 1 -d ':')" -- "${cur}") )
} }
function _tmux_complete_session() { function _tmux_complete_session() {
local IFS=$'\n' local IFS=$'\n'
local cur="${1}" local cur="${1}"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-sessions | cut -f 1 -d ':')" -- "${cur}") ) COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-sessions 2>/dev/null | cut -f 1 -d ':')" -- "${cur}") )
} }
function _tmux_complete_window() { function _tmux_complete_window() {
local IFS=$'\n' local IFS=$'\n'
@ -47,10 +131,10 @@ function _tmux_complete_window() {
local session_name="$(echo "${cur}" | sed 's/\\//g' | cut -d ':' -f 1)" local session_name="$(echo "${cur}" | sed 's/\\//g' | cut -d ':' -f 1)"
local sessions local sessions
sessions="$(tmux -q list-sessions | sed -re 's/([^:]+:).*$/\1/')" sessions="$(tmux -q list-sessions 2>/dev/null | sed -re 's/([^:]+:).*$/\1/')"
if [[ -n "${session_name}" ]]; then if [[ -n "${session_name}" ]]; then
sessions="${sessions} sessions="${sessions}
$(tmux -q list-windows -t "${session_name}" | sed -re 's/^([^:]+):.*$/'"${session_name}"':\1/')" $(tmux -q list-windows -t "${session_name}" 2>/dev/null | sed -re 's/^([^:]+):.*$/'"${session_name}"':\1/')"
fi fi
cur="$(echo "${cur}" | sed -e 's/:/\\\\:/')" cur="$(echo "${cur}" | sed -e 's/:/\\\\:/')"
sessions="$(echo "${sessions}" | sed -e 's/:/\\\\:/')" sessions="$(echo "${sessions}" | sed -e 's/:/\\\\:/')"
@ -102,8 +186,7 @@ _tmux() {
if [[ $COMP_CWORD -le $cmd_index ]]; then if [[ $COMP_CWORD -le $cmd_index ]]; then
# The user has not specified a command yet # The user has not specified a command yet
local all_commands="$(tmux -q list-commands | cut -f 1 -d ' ')" COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${_tmux_cmds}" -- "${cur}") )
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${all_commands}" -- "${cur}") )
else else
case ${cmd} in case ${cmd} in
attach-session|attach) attach-session|attach)