基于svn ls 实现的SVN目录自动补全

本文介绍了一个用于 SVN 的自动补全脚本实现,该脚本通过 bash shell 编程来完成对 svn checkout 命令的路径补全功能。通过分析当前输入的状态,该脚本可以提供相应的目录或文件选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考了系统自带的cd 自动补全功能

参考网址:
http://kodango.com/bash-competion-programming
http://www.2cto.com/kf/201609/551995.html
http://www.jb51.net/article/56563.htm
系统版本:
Protobuf.noteRed Hat 4.8.2-16

shell代码:

# .svn co
#svn co 的补全功能
echo "dtcwyp svn co"

function svn_co()
{
    local IFS=$'\n'
    START_DIR="svn://192.168.0.6/svn/"
    COMPREPLY=()
    local input1 input2 input3 input5 input6
    local -a input4
    local z y
    input1="${COMP_WORDS[0]}"
    input2="${COMP_WORDS[1]}"
    input5="${COMP_WORDS[2]}"
    input6="${COMP_WORDS[3]}"
    for((i=4;i<=$COMP_CWORD;i++));do
        z="$z${COMP_WORDS[$i]}"
    done
    input3=$(echo "${z}"|sed 's/\\//g')

    if [[ $input2 = "co" ]] && [[ $input1 = "svn" ]];then
        if [ -z "$input3" ];then
            COMPREPLY=( $(compgen -W "$START_DIR" -- ) )
        else
            y=`svn ls ${input5}${input6}${input3%/*}/ 2>/dev/null`
            if [[ ! -n $y ]];then
                #echo "START_DIR is error,can't get list"
                return 0
            fi
            x=$(compgen -W "${y}" -- ${input3##*/})
            while read "LINE"
            do
                input4+=( "${input3%/*}/$LINE" )
            done <<< "$x"

            if [[ ${#input4[@]} -ne 0 ]]; then
                compopt -o filenames 2>/dev/null
                COMPREPLY+=( "${input4[@]}" )
            fi
        fi
    fi
}
echo "support svn co complete"
complete -o nospace -F svn_co svn co
echo ""
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值