您的位置:首页 > 运维架构 > Shell

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

2017-03-24 14:24 260 查看
参考了系统自带的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 ""
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell自动补全