Tmux komutunu yazarken tamamlama sekmesi nasıl yapılır?


22

Bazı komutlar ( kill-sessionve kill-server) aynı ön eke sahiptir.
( prefix:kill-seTab) Yazdığımda tmux bana sonuç vermiyor.
Tmux içinde otomatik tamamlama için joker menüsünü göstermek için bir seçenek var mı?

Ubuntu 12.04 kullanıyorum


Hangi kabuğu kullanıyorsunuz? Sen echo $ SHELL ile bulabilirsiniz
éclairevoyant

1
Bu/bin/bash
kev

4
Kabuk nasıl ilişkilidir? Eğer yazdığınızda Ctrl + B ,: tmux içinde, siz (sadece yazarken gibi.: VIM, istemi bir bash verilen değiliz) istemi bir tmux komutu verilen konum Bu tmux soru değil, bir kabuk sorudur.
bobpaul

Bash tamamlama cevabı faydalıdır, ancak tmux'ta kullanılacak soruyu cevaplamaz. Tmux'un çalışmak için fazladan bir dikey alan çizgisi olmadığı için, bash gibi sekme tamamlama seçeneklerini sunmuyor, en azından yazana kadar yazdığınız şeyi tamamlıyor. belirsizlik. Böylece millet öğrenmek için bash seçeneğini kullanabilir ve ne istediklerini bildikleri quicki'lerde tmux seçeneğini kullanabilir.
nealmcb

Yanıtlar:


8

Aşağıdaki komut tmux için bir bash tamamlama sağlar ve hemen şimdi kutumda denedim ve harika çalışıyor. Sadece betiği bilgisayarınızdaki bir dosyaya kopyalayın ve

   source /path/to/tmux_completion.sh

senin içinde .bashrcve gitmeye hazır olmalısın.


#!/bin/bash

# tmux completion
# See: http://www.debian-administration.org/articles/317 for how to write more.
# Usage: Put "source bash_completion_tmux.sh" into your .bashrc
# Based upon the example at http://paste-it.appspot.com/Pj4mLycDE

_tmux_expand () 
{ 
    [ "$cur" != "${cur%\\}" ] && cur="$cur"'\';
    if [[ "$cur" == \~*/* ]]; then
        eval cur=$cur;
    else
        if [[ "$cur" == \~* ]]; then
            cur=${cur#\~};
            COMPREPLY=($( compgen -P '~' -u $cur ));
            return ${#COMPREPLY[@]};
        fi;
    fi
}

_tmux_filedir () 
{ 
    local IFS='
';
    _tmux_expand || return 0;
    if [ "$1" = -d ]; then
        COMPREPLY=(${COMPREPLY[@]} $( compgen -d -- $cur ));
        return 0;
    fi;
    COMPREPLY=(${COMPREPLY[@]} $( eval compgen -f -- \"$cur\" ))
}

function _tmux_complete_client() {
    local IFS=$'\n'
    local cur="${1}"
    COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-clients | cut -f 1 -d ':')" -- "${cur}") )
}
function _tmux_complete_session() {
    local IFS=$'\n'
    local cur="${1}"
    COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-sessions | cut -f 1 -d ':')" -- "${cur}") )
}
function _tmux_complete_window() {
    local IFS=$'\n'
    local cur="${1}"
    local session_name="$(echo "${cur}" | sed 's/\\//g' | cut -d ':' -f 1)"
    local sessions

    sessions="$(tmux -q list-sessions | sed -re 's/([^:]+:).*$/\1/')"
    if [[ -n "${session_name}" ]]; then
        sessions="${sessions}
$(tmux -q list-windows -t "${session_name}" | sed -re 's/^([^:]+):.*$/'"${session_name}"':\1/')"
    fi
    cur="$(echo "${cur}" | sed -e 's/:/\\\\:/')"
    sessions="$(echo "${sessions}" | sed -e 's/:/\\\\:/')"
    COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${sessions}" -- "${cur}") )
}

_tmux() {
    local cur prev
    local i cmd cmd_index option option_index
    local opts=""
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    if [ ${prev} == -f ]; then
        _tmux_filedir
    else
    # Search for the command
    local skip_next=0
    for ((i=1; $i<=$COMP_CWORD; i++)); do
        if [[ ${skip_next} -eq 1 ]]; then
            #echo "Skipping"
            skip_next=0;
        elif [[ ${COMP_WORDS[i]} != -* ]]; then
            cmd="${COMP_WORDS[i]}"
            cmd_index=${i}
            break
        elif [[ ${COMP_WORDS[i]} == -f ]]; then
            skip_next=1
        fi
    done

    # Search for the last option command
    skip_next=0
    for ((i=1; $i<=$COMP_CWORD; i++)); do
        if [[ ${skip_next} -eq 1 ]]; then
            #echo "Skipping"
            skip_next=0;
        elif [[ ${COMP_WORDS[i]} == -* ]]; then
            option="${COMP_WORDS[i]}"
            option_index=${i}
            if [[ ${COMP_WORDS[i]} == -- ]]; then
                break;
            fi
        elif [[ ${COMP_WORDS[i]} == -f ]]; then
            skip_next=1
        fi
    done

    if [[ $COMP_CWORD -le $cmd_index ]]; then
        # The user has not specified a command yet
        local all_commands="$(tmux -q list-commands | cut -f 1 -d ' ')"
        COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${all_commands}" -- "${cur}") )
    else        
        case ${cmd} in
            attach-session|attach)
            case "$prev" in
                -t) _tmux_complete_session "${cur}" ;;
                *) options="-t -d" ;;
            esac ;;
            detach-client|detach)
            case "$prev" in
                -t) _tmux_complete_client "${cur}" ;;
                *) options="-t" ;;
            esac ;;
            lock-client|lockc)
            case "$prev" in
                -t) _tmux_complete_client "${cur}" ;;
                *) options="-t" ;;
            esac ;;
            lock-session|locks)
            case "$prev" in
                -t) _tmux_complete_session "${cur}" ;;
                *) options="-t -d" ;;
            esac ;;
            new-session|new)
            case "$prev" in
                -t) _tmux_complete_session "${cur}" ;;
                -[n|d|s]) options="-d -n -s -t --" ;;
                *) 
                if [[ ${COMP_WORDS[option_index]} == -- ]]; then
                    _command_offset ${option_index}
                else
                    options="-d -n -s -t --"
                fi
                ;;
            esac
            ;;
            refresh-client|refresh)
            case "$prev" in
                -t) _tmux_complete_client "${cur}" ;;
                *) options="-t" ;;
            esac ;;
            rename-session|rename)
            case "$prev" in
                -t) _tmux_complete_session "${cur}" ;;
                *) options="-t" ;;
            esac ;;
            source-file|source) _tmux_filedir ;;
            has-session|has|kill-session)
            case "$prev" in
                -t) _tmux_complete_session "${cur}" ;;
                *) options="-t" ;;
            esac ;;
            suspend-client|suspendc)
            case "$prev" in
                -t) _tmux_complete_client "${cur}" ;;
                *) options="-t" ;;
            esac ;;
            switch-client|switchc)
            case "$prev" in
                -c) _tmux_complete_client "${cur}" ;;
                -t) _tmux_complete_session "${cur}" ;;
                *) options="-l -n -p -c -t" ;;
            esac ;;

            send-keys|send)
            case "$option" in
                -t) _tmux_complete_window "${cur}" ;;
                *) options="-t" ;;
            esac ;;
          esac # case ${cmd}
        fi # command specified
      fi # not -f 

      if [[ -n "${options}" ]]; then
          COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${options}" -- "${cur}") )
      fi

      return 0

}
complete -F _tmux tmux

# END tmux completion

Komut Dosyası Kaynağı


5
Bu senaryoyu sakladım ve .bashrc'den aldım. Tmux’a başladım ve "Ctrl + B,:" tuşlarına bastım, sonra da "detach" yazdım ve bir demet sekmeye bastım. Hiçbir şey değil. Ac ekledim, böylece "detach-c" deyin ve sekmeye basın, "datach-client" olarak tamamladı. Bu senaryodan önce yaşadığım aynı davranış. Hiçbir şey değişmemiş gibi görünüyor.
bobpaul

6
@ bobpaul, basm gibi bir kabuğundan değil, tmux içinde sekme tamamlamayı istiyor.
Jason Axelson,

1
@kev ayrıca basm'dan değil tmux'da sekme tamamlamayı istiyor. Ve bu bash komutu tamamlama yaklaşımı için bazı (daha eski?) Kodların github.com/aziz/dotfiles/blob/master/bash/completion/… adresindeki github'da olduğuna dikkat edin, ancak davranışlarının nasıl değiştiği açık değil. Belki luolimao farkları bir çekme talebinde sunmak isteyebilir mi?
nealmcb

Bu otomatik tamamlama komut dosyası Bash'de harika çalışıyor! @Luolimao teşekkürler!
Trevor Sullivan

2
Yanıtı aşağıya oyladım, çünkü OP bash için değil, tmux içinden otomatik tamamlamayı istiyor. Bu cevap ikinci sorgulama için tamamen makul olabilir (bash için tamamlanma), ancak tmux içinden bir tamamlama bulmaya çalışmak için arama motorlarından gelenleri yanıltıcıdır.
thiagowfx
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.