使用vimdiff替换默认的'svn diff'


手动配置


第一步,配置 .vimrc

目标:vimdiff可以快速wrap很长的一行信息自动换行

" ~/.vimrc

"BEGIN for vimdiff
func Wrap()
  set wrap
endfunc
map  :call Wrap() :call Wrap()
imap  :call Wrap() :call Wrap()
"END for vimdiff

第二步,配置 ~/.subversion/config

目标:替换svn diff默认的对比工具为自定义的一个脚本,如果不爽,再改回来。

### Set diff-cmd to the absolute path of your 'diff' program.
###   Subversion's internal diff implementation.
# diff-cmd = diff_program (diff, gdiff, etc.)
diff-cmd = /home/xiwang/usr/local/bin/diffwrap.sh

第三步,创建/编辑 diffwrap.sh

目标:实现diffwrap.sh脚本,使执行命令'svn diff'时能正确执行此vimdiff命令。

#!/bin/bash

# diffwrap.sh

# ---BEGIN--- change
#shift 5
#vimdiff "$@"
DIFF="vimdiff"
LEFT=${6}
RIGHT=${7}

$DIFF $LEFT $RIGHT
# ----END---- change

脚本可以升级一下,通过环境变量DIFF来控制使用哪个diff命令,例如想要实用vimdiff的时候,就可以直接运行命令:export DIFF=vimdiff; 即可:

#!/bin/bash
# @input environment DIFF='diff'|'vimdiff'

# ---BEGIN--- change
# DIFF="diff"
# LEFT=${6}
# RIGHT=${7}
#
# $DIFF "$LEFT" "$RIGHT"

if [ x"$DIFF" == x"" ]; then
    DIFF="diff"; export DIFF
fi

LEFT=${6}
RIGHT=${7}

case "$DIFF" in
    "vimdiff")
        ;;
    "diff")
        OPTS="-Nu"
        ;;
esac

$DIFF "$LEFT" "$RIGHT" $OPTS
# ----END---- change



你可能感兴趣的:(Bash,Shell,bash,Linux)