笔记:svn操作优化,在bash中通过别名实现svn代码仓库的在线操作

一、TortoiseSVN

使用过SVN的应该都知道TortoiseSVN,界面操作简单方便,易上手。

二、SVN命令行

如果想在命令行中操作代码仓库,必须把代码下下来,才能在目录间切换,如果代码仓库中的代码量很大,全部下下来非常不现实,既占用磁盘空间又耗时。

三、自定义别名

通过对svn的常见操作做别名处理,通过别名来实现命令行中对svn代码仓库目录的切换。对于喜欢用命令行来操作的人来说是一个不错的方法,别名示例如下:

#将GBK转为UTF8
alias utf8_iconv='iconv -f GBK -t UTF-8'

#svn操作相关
svn_path="https://127.0.0.1/test/"
alias svn_pwd='echo $svn_path'
alias svn_info='svn info "$svn_path"'
alias svn_..='svn_path=$(dirname "$svn_path") && svn_pwd'

function svn_log(){
    svn log "$*" "$svn_path" | utf8_iconv
}

function svn_ls(){
    if [[ ${svn_path: -1} == "/" ]]; then
        svn_path_ls="${svn_path}$1"
    else
        svn_path_ls="$svn_path/$1"
    fi
    svn list "$svn_path_ls" | utf8_iconv
}

function svn_cd(){
    if [[ ${svn_path: -1} == "/" ]]; then
        svn_path="${svn_path}$1"
    else
        svn_path="$svn_path/$1"
    fi
    svn_pwd
}

function _svn_cd()
{
    local i
    local toDir="$2"
    local absDir=$svn_path/$toDir
    local toDirPre
    local toDirBase

    absDir=${absDir//\/\//\/}
    absDir=${absDir//:\//:\/\/}

    if [[ ${absDir: -1} != "/" ]]; then
        absDir=$(dirname $absDir)
    fi

    local OLD_IFS=$IFS
    local IFS=$'\r\n'

    if [[ ${toDir: -1} == "/" ]]; then
        toDirPre=$toDir
        COMPREPLY=($(svn list "$absDir" | utf8_iconv))
    else
        toDirPre=$(dirname "$toDir")
        toDirBase=$(basename "$toDir")
        COMPREPLY=($(svn list "$absDir" | utf8_iconv | grep -E "^$toDirBase"))
    fi

    IFS=$OLD_IFS

    if [[ $toDirPre != "." ]]; then
        for((i=0; i < ${#COMPREPLY[@]}; i++));
        do
            if [[ ${toDirPre: -1} == "/" ]]; then
                COMPREPLY[$i]=$toDirPre${COMPREPLY[$i]}
            else
                COMPREPLY[$i]=$toDirPre/${COMPREPLY[$i]}
            fi
        done
    fi

    return 0
}

# 为 svn_cd 增加 tab 键自动提示
complete -o nospace -o filenames -F _svn_cd svn_cd
complete -o nospace -o filenames -F _svn_cd svn_ls

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值