[20150422]tmux bash_completion.txt

[20150422]tmux bash_completion.txt

--正在学习tmux,需要一个命令补全程序,找了很久,源码自带的太简单,不是很好用.
--找了N久,发现别人配置的,链接如下:

https://github.com/aziz/dotfiles/blob/master/bash/completion/tmux.completion.bash

#!/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

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
        _filedir
    else
    # Search for the command
    local skip_next=0
    for ((i=1; $i        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        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) _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

--也有一些小问题,暂时凑合着用吧.

时间: 2024-07-30 10:47:46

[20150422]tmux bash_completion.txt的相关文章

[20141225]学习使用tmux心得.txt

[20141225]学习使用tmux心得.txt --前一段时间由于工作需要,学习使用tmux. tmux is a "terminal multiplexer". It allows a number of terminals (or windows) to be accessed and controlled from a single terminal. It is intended to be a simple, modern, BSD-licensed alternative

[20150529]man tmux less.txt

[20150529]man tmux less.txt --在linux下有一个小问题(我测试几个版本都存在这个问题),如果在tmux下使用man显示文档时,如果按q退出,会清除屏幕显示.导致我无 --法根据文档打入命令,我希望在退出后屏幕的显示信息保留在屏幕上. --如果不在tmux下使用正常. --最先想到的是终端仿真的问题. --在tmux下: $  echo $TERM screen --一般putty登陆: #  echo $TERM linux --一直想从上面终端仿真上找原因,能力

[20150425]tmux学习心得2.txt

[20150425]tmux学习心得2.txt --学习使用tmux有一段时间,本来不想在这个上面花太多时间的,自己还抽空看了2篇电子书籍: Apress.tmux.Taster.1484207769.pdf Pragmatic.tmux.Feb.2012.pdf -- 自己总结一下学习心得: 1.关于prefix key: --我前面提到我最终选择ctrl+a作为prefix key.实际上要避开冲突有一定难度. prefix key 的缺省定义是ctrl-b,实际上有一些修改成ctrl-a或

[20170119]tmux与环境变量.txt

[20170119]tmux与环境变量.txt tmux是我的最爱,我基本登录linux马上切换到tmux,进行多屏幕的管理操作.最近遇到1个与环境变量有关的问题. 1.环境: $ cat /etc/issue Oracle Linux Server release 5.9 Kernel \r on an \m $  tmux  -V tmux 1.6 --//我使用tmux版本并不高. 2.建立环境变量: --//linux 会话1 $ export AAA=1111 $ echo $AAA

[20170711]关于tmux共享会话问题.txt

[20170711]关于tmux共享会话问题.txt --//星期6,7看了一些tmux相关数据,学习如何共享会话,老外给它起一个很好听的名字叫做结对编程(Pair Programming). --//参考书籍Pragmatic.Bookshelf.tmux.2.Productive.Mouse-Free.Development.1680502212.pdf 1.做简单的方法: --session 1 : $ tmux --session 2 : $ tmux attach 2.上面例子很简单,

[20170708]tmux script例子.txt

[20170708]tmux script例子.txt --//上个星期解决rac ora-12514问题时,因为要打开多个窗口,非常麻烦,利用星期6,7看了一些文档,写一个tmux script: --//便于以后工作需要: #! /bin/bash tmux has-session -t oracle if [ $? != 0 ]; then   tmux new-session -s oracle -d   tmux new-window -n bashgrid -t oracle   t

[20150427]tmux与INPUTRC定义冲突.txt

[20150427]tmux与INPUTRC定义冲突.txt --我前一阵子发现在tmux里面一些按键与INPUTRC冲突. 我的/etc/inputrc定义如下: "\e[1~": beginning-of-line    # home "\e[2~": yank-last-arg        # insert "\e[3~": delete-char          # delete "\e[4~": end-of-l

linux下的终端利器----tmux

tmux 简介 我想大家之前都听说过terminator ,这个多终端管理器,之前我也一直使用的这个,但是使用起来感觉有点丑陋,而且使用起来非常不方便.但是这个tmux 却可以使你排抛弃键盘,完全使用键盘操作. tmux 是指通过一个终端登录远程主机并运行后,在其中可以开启多个控制台的终端复用软件.类似GNU Screen,但来自于OpenBSD,采用BSD授权.使用它最直观的好处就是,通过一个终端登录远程主机并运行tmux后,在其中可以开启多个控制台而无需再"浪费"多余的终端来连接这

打造高效前端工作环境 - tmux

打造高效前端工作环境 - tmux 前言  现在前端开发可不容易啊,先打开个VIM,然后再打开个lite-server,一不小心写个ES2015还要打开个gulp来做预编译,如果能把这么多个窗口放在一个工作台上那就好了.咦,tmux不就专干这事的吗? tmux入门 安装sudo apt install tmux tmux的C/S架构 服务端(Server), 1个服务端维护1-N个会话; 会话(Session), 1个会话对应1~N个窗口; 窗口(Window), 1个窗口对应1~N个窗格; 窗