-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim比较目录diff.html
506 lines (485 loc) · 29.6 KB
/
vim比较目录diff.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="littlewhite" />
<meta name="copyright" content="littlewhite" />
<meta property="og:type" content="article" />
<meta name="twitter:card" content="summary">
<meta name="keywords" content="vim, Skill, " />
<meta property="og:title" content="vim比较目录diff "/>
<meta property="og:url" content="https://chukeer.github.io/vim比较目录diff.html" />
<meta property="og:description" content="虽然现在有很多图形界面的diff工具,但对于有命令行情节的人来说,当飞快的在terminal下敲击键盘时,总不希望再拿鼠标去点击其它地方,况且有时候图形界面占用资源多,我的MBA就经常启动diffmerge时卡住,但vimdiff又只能在一个标签里比较一组文件的diff,如果想比较两个目录下文件的diff,它就显得无能为力了 假设我们要实现一个工具叫diffdir,先让我们脑洞打开设想一下它应该是怎样的 我希望能列出两个目录下文件名相同但内容不同的所有文件,并进行编号 我希望通过选择编号,打开需要比较diff的文件 如果想比较多组文件的diff,我希望每个vim标签打开一组文件比较 最好能过滤掉非文本文件,因为我不希望用vim打开一对二进制乱码 最好还能有交互,我可以选择只查看我感兴趣的文件,而不是一次打开所有文件的diff,当退出vim时我还可以继续选择 假设有两个目录分别是A和B,目录结构如下 A ├── file1 ├── file2 └── file3 B和A目录结构以及对应文件名都相同,其中file1和file2的内容不同,file3内容相同,那么当我们运行diffdir A B时,它应该是这样的界面 当我们选择编号1时,vim会打开一个标签对比两个目录下file1的差异 当我们选择1,2或1-2时,vim会打开两个标签分别比较file1和file2的差异 由于这个例子有diff的文件数量较少,我们还可以选择a一次打开所有文件的diff 如果diff文件个数较多 ..." />
<meta property="og:site_name" content="楚客" />
<meta property="og:article:author" content="littlewhite" />
<meta property="og:article:published_time" content="2015-04-27T00:00:00+08:00" />
<meta property="" content="2015-04-27T00:00:00+08:00" />
<meta name="twitter:title" content="vim比较目录diff ">
<meta name="twitter:description" content="虽然现在有很多图形界面的diff工具,但对于有命令行情节的人来说,当飞快的在terminal下敲击键盘时,总不希望再拿鼠标去点击其它地方,况且有时候图形界面占用资源多,我的MBA就经常启动diffmerge时卡住,但vimdiff又只能在一个标签里比较一组文件的diff,如果想比较两个目录下文件的diff,它就显得无能为力了 假设我们要实现一个工具叫diffdir,先让我们脑洞打开设想一下它应该是怎样的 我希望能列出两个目录下文件名相同但内容不同的所有文件,并进行编号 我希望通过选择编号,打开需要比较diff的文件 如果想比较多组文件的diff,我希望每个vim标签打开一组文件比较 最好能过滤掉非文本文件,因为我不希望用vim打开一对二进制乱码 最好还能有交互,我可以选择只查看我感兴趣的文件,而不是一次打开所有文件的diff,当退出vim时我还可以继续选择 假设有两个目录分别是A和B,目录结构如下 A ├── file1 ├── file2 └── file3 B和A目录结构以及对应文件名都相同,其中file1和file2的内容不同,file3内容相同,那么当我们运行diffdir A B时,它应该是这样的界面 当我们选择编号1时,vim会打开一个标签对比两个目录下file1的差异 当我们选择1,2或1-2时,vim会打开两个标签分别比较file1和file2的差异 由于这个例子有diff的文件数量较少,我们还可以选择a一次打开所有文件的diff 如果diff文件个数较多 ...">
<title>vim比较目录diff · 楚客
</title>
<!--
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.1/css/font-awesome.css" rel="stylesheet">
--!>
<link href="https://chukeer.github.io/theme/css/bootstrap-combined.min.css" rel="stylesheet">
<link href="https://chukeer.github.io/theme/css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://chukeer.github.io/theme/css/pygments.css" media="screen">
<link rel="stylesheet" type="text/css" href="https://chukeer.github.io/theme/tipuesearch/tipuesearch.css" media="screen">
<link rel="stylesheet" type="text/css" href="https://chukeer.github.io/theme/css/elegant.css" media="screen">
<link rel="stylesheet" type="text/css" href="https://chukeer.github.io/theme/css/custom.css" media="screen">
</head>
<body>
<div id="content-sans-footer">
<div class="navbar navbar-static-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="https://chukeer.github.io/"><span class=site-name>楚客</span></a>
<div class="nav-collapse collapse">
<ul class="nav pull-right top-menu">
<li ><a href="https://chukeer.github.io">Home</a></li>
<li ><a href="https://chukeer.github.io/categories.html">Categories</a></li>
<li ><a href="https://chukeer.github.io/tags.html">Tags</a></li>
<li ><a href="https://chukeer.github.io/archives.html">Archives</a></li>
<li><form class="navbar-search" action="https://chukeer.github.io/search.html" onsubmit="return validateForm(this.elements['q'].value);"> <input type="text" class="search-query" placeholder="Search" name="q" id="tipue_search_input"></form></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span1"></div>
<div class="span10">
<article>
<div class="row-fluid">
<header class="page-header span10 offset2">
<h1><a href="https://chukeer.github.io/vim比较目录diff.html"> vim比较目录diff </a></h1>
</header>
</div>
<div class="row-fluid">
<div class="span2 table-of-content">
<nav>
<h4>Contents</h4>
<div class="toc">
<ul>
<li><a href="#vimdiff">vim比较文件diff</a></li>
<li><a href="#vimdiff_1">vim在新标签比较文件diff</a></li>
<li><a href="#vim">vim批量执行命令</a></li>
<li><a href="#_1">最终实现</a></li>
</ul>
</div>
</nav>
</div>
<div class="span8 article-content">
<p>虽然现在有很多图形界面的diff工具,但对于有命令行情节的人来说,当飞快的在terminal下敲击键盘时,总不希望再拿鼠标去点击其它地方,况且有时候图形界面占用资源多,我的MBA就经常启动diffmerge时卡住,但vimdiff又只能在一个标签里比较一组文件的diff,如果想比较两个目录下文件的diff,它就显得无能为力了</p>
<p>假设我们要实现一个工具叫diffdir,先让我们脑洞打开设想一下它应该是怎样的</p>
<ol>
<li>我希望能列出两个目录下文件名相同但内容不同的所有文件,并进行编号</li>
<li>我希望通过选择编号,打开需要比较diff的文件</li>
<li>如果想比较多组文件的diff,我希望每个vim标签打开一组文件比较</li>
<li>最好能过滤掉非文本文件,因为我不希望用vim打开一对二进制乱码</li>
<li>最好还能有交互,我可以选择只查看我感兴趣的文件,而不是一次打开所有文件的diff,当退出vim时我还可以继续选择</li>
</ol>
<p>假设有两个目录分别是A和B,目录结构如下</p>
<div class="highlight"><pre><span></span>A
├── file1
├── file2
└── file3
</pre></div>
<p>B和A目录结构以及对应文件名都相同,其中file1和file2的内容不同,file3内容相同,那么当我们运行<code>diffdir A B</code>时,它应该是这样的界面</p>
<p><img alt="" src="http://littlewhite.us/pic/20150427/1.png"/></p>
<p>当我们选择编号1时,vim会打开一个标签对比两个目录下file1的差异<br/>
当我们选择<code>1,2</code>或<code>1-2</code>时,vim会打开两个标签分别比较file1和file2的差异<br/>
由于这个例子有diff的文件数量较少,我们还可以选择a一次打开所有文件的diff<br/>
如果diff文件个数较多,我们可以分批打开,并且当我们退出vim后还可以继续选择</p>
<p>接下来是实现</p>
<h3 id="vimdiff">vim比较文件diff<a class="headerlink" href="#vimdiff" title="Permanent link">¶</a></h3>
<p>我们都知道vimdiff的用法,其实<code>vimdiff A/file1 B/file1</code>等价于<code>vim -d A/file1 B/file2</code>,又或者更原始一点,我们可以分两步来比较两个文件的diff</p>
<ol>
<li>执行<code>vim A/file1</code></li>
<li>在normal模式下输入<code>:vertical diffsplit B/file1</code></li>
</ol>
<p>虽然人们不会用这么麻烦的命令去比价文件的diff,但往往最基本的命令反而能组合出更多的功能,就像搭积木一样,我们只需要几个基本的形状,就可以通过自己的想象搭建多彩的世界,而vim的这些基本命令就像积木一样,我们要做的是利于好这些积木</p>
<h3 id="vimdiff_1">vim在新标签比较文件diff<a class="headerlink" href="#vimdiff_1" title="Permanent link">¶</a></h3>
<p>假设我们已经用上面的命令打开了vim并比较file1的diff,如果我们希望新建一个标签来比较file2的diff呢,还是要用到基本的ex命令</p>
<ol>
<li>在normal模式下执行<code>:tabnew A/file2</code></li>
<li>在normal模式下执行<code>:vertical diffsplit B/file1</code></li>
</ol>
<h3 id="vim">vim批量执行命令<a class="headerlink" href="#vim" title="Permanent link">¶</a></h3>
<p>以上两个示例就是我们需要的积木,有了积木,我们就可以组合出强大的命令,现在要做的是同时打开两组文件的diff,并且每个标签一组diff</p>
<p>通过查看vim帮助我们发现vim有如下两个参数</p>
<div class="highlight"><pre><span></span>-c <command> 加载第一个文件后执行 <command>
-S <session> 加载第一个文件后执行文件 <session>
</pre></div>
<p>这两个参数都可以让vim启动时执行一些命令,其中-c是从参数读取命令,-S是从文件读取命令,于是我们就可以将需要执行的命令存入文件,启动vim时通过-S参数加载该文件,就能达到我们批量执行命令的目的。假设我们需要打开两个标签,分别比较A,B目录下file1和file2的diff,事先创建vim.script如下(文件名随意,最好采用绝对路径,以免受到vim配置里autochdir的影响)</p>
<div class="highlight"><pre><span></span>edit A/file1
vertical diffsplit B/file1
tabnew A/file2
vertical diffsplit B/file2
</pre></div>
<p>然后执行<code>vim -S vim.script</code>,看看是否如你所愿,打开了两个标签,分别比较file1和file2的diff。注意,为了</p>
<h3 id="_1">最终实现<a class="headerlink" href="#_1" title="Permanent link">¶</a></h3>
<p>既然有了这些积木,那我们就可以灵活的根据需要编写脚本实现我们的需求,下面是我最终的实现,也可以在github上查看源码</p>
<p><a href="https://github.com/handy1989/vim/blob/master/diffdir">https://github.com/handy1989/vim/blob/master/diffdir</a></p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="ch">#!/bin/bash</span>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$#</span> -ne <span class="m">2</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="nb">echo</span> <span class="s2">"Usage:</span><span class="nv">$0</span><span class="s2"> dir1 dir2"</span>
<span class="nb">exit</span> 1
<span class="k">fi</span>
<span class="k">if</span> <span class="o">[</span> ! -d <span class="nv">$1</span> -o ! -d <span class="nv">$2</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="nb">echo</span> <span class="s2">"</span><span class="nv">$1</span><span class="s2"> or </span><span class="nv">$2</span><span class="s2"> is not derectory!"</span>
<span class="nb">exit</span> 1
<span class="k">fi</span>
<span class="c1">## 注意,Mac的readlink程序和GNU readlink功能不同,Mac需要下载greadlink</span>
<span class="nv">arg1</span><span class="o">=</span><span class="sb">`</span>greadlink -f <span class="nv">$1</span><span class="sb">`</span>
<span class="nv">arg2</span><span class="o">=</span><span class="sb">`</span>greadlink -f <span class="nv">$2</span><span class="sb">`</span>
<span class="nv">tmp_dir</span><span class="o">=</span>/tmp/tmp.<span class="nv">$$</span>
rm -rf <span class="nv">$tmp_dir</span>
mkdir -p <span class="nv">$tmp_dir</span> <span class="o">||</span> <span class="nb">exit</span> 0
<span class="c1">#echo $tmp_dir</span>
<span class="nb">trap</span> <span class="s2">"rm -rf </span><span class="nv">$tmp_dir</span><span class="s2">; exit 0"</span> SIGINT SIGTERM
<span class="c1">## 注意,Mac和Linux的MD5程序不同,请根据需求使用,这里是Mac版的用法</span>
<span class="k">function</span> get_file_md5
<span class="o">{</span>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$#</span> -ne <span class="m">1</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="nb">echo</span> <span class="s2">"get_file_md5 arg num error!"</span>
<span class="k">return</span> 1
<span class="k">fi</span>
<span class="nb">local</span> <span class="nv">file</span><span class="o">=</span><span class="nv">$1</span>
md5 <span class="nv">$file</span> <span class="p">|</span> awk -F<span class="s2">"="</span> <span class="s1">'{print $2}'</span>
<span class="o">}</span>
<span class="k">function</span> myexit
<span class="o">{</span>
rm -rf <span class="nv">$tmp_dir</span>
<span class="nb">exit</span> 0
<span class="o">}</span>
<span class="k">function</span> show_diff
<span class="o">{</span>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$#</span> -ne <span class="m">1</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="k">return</span> 1
<span class="k">fi</span>
<span class="nb">local</span> <span class="nv">diff_file</span><span class="o">=</span><span class="nv">$1</span>
<span class="nb">echo</span> <span class="s2">"diff file:"</span>
<span class="nb">printf</span> <span class="s2">" %-55s %-52s\n"</span> <span class="nv">$arg1</span> <span class="nv">$arg2</span>
<span class="k">if</span> <span class="o">[</span> -f <span class="nv">$tmp_dir</span>/A_ony_file <span class="o">]</span><span class="p">;</span><span class="k">then</span>
awk <span class="s1">'{printf(" [%2d] %-50s\n", NR, $1)}'</span> <span class="nv">$tmp_dir</span>/A_ony_file
python -c <span class="s1">'print "-"*100'</span>
<span class="k">fi</span>
awk <span class="s1">'{printf(" [%2d] %-50s %-50s\n", NR, $1, $1)}'</span> <span class="nv">$diff_file</span>
<span class="nb">echo</span> <span class="s2">"(s):show diff files (a):open all diff files (q):exit"</span>
<span class="nb">echo</span>
<span class="o">}</span>
<span class="k">function</span> check_value
<span class="o">{</span>
<span class="nb">local</span> <span class="nv">diff_file</span><span class="o">=</span><span class="nv">$1</span>
<span class="nb">local</span> <span class="nv">value</span><span class="o">=</span><span class="nv">$2</span>
<span class="nv">tmp_file</span><span class="o">=</span><span class="nv">$tmp_dir</span>/tmp_file
><span class="nv">$tmp_file</span>
<span class="k">for</span> numbers in <span class="sb">`</span><span class="nb">echo</span> <span class="s2">"</span><span class="nv">$value</span><span class="s2">"</span> <span class="p">|</span> tr <span class="s1">','</span> <span class="s1">' '</span><span class="sb">`</span>
<span class="k">do</span>
<span class="nv">nf</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> <span class="s2">"</span><span class="nv">$numbers</span><span class="s2">"</span> <span class="p">|</span> awk -F<span class="s2">"-"</span> <span class="s1">'{print NF}'</span><span class="sb">`</span>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$nf</span> -ne <span class="m">1</span> -a <span class="nv">$nf</span> -ne <span class="m">2</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="k">return</span> 1
<span class="k">fi</span>
<span class="nv">begin</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> <span class="s2">"</span><span class="nv">$numbers</span><span class="s2">"</span> <span class="p">|</span> awk -F<span class="s2">"-"</span> <span class="s1">'{print $1}'</span><span class="sb">`</span>
<span class="nv">end</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> <span class="s2">"</span><span class="nv">$numbers</span><span class="s2">"</span> <span class="p">|</span> awk -F<span class="s2">"-"</span> <span class="s1">'{print $2}'</span><span class="sb">`</span>
<span class="k">if</span> <span class="o">[</span> -z <span class="s2">"</span><span class="nv">$end</span><span class="s2">"</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
sed -n <span class="nv">$begin</span><span class="s1">'p'</span> <span class="nv">$diff_file</span> >> <span class="nv">$tmp_file</span>
<span class="k">else</span>
<span class="k">if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$end</span><span class="s2">"</span> -lt <span class="nv">$begin</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="k">return</span> 1
<span class="k">fi</span>
sed -n <span class="nv">$begin</span><span class="s1">','</span><span class="nv">$end</span><span class="s1">'p'</span> <span class="nv">$diff_file</span> >> <span class="nv">$tmp_file</span>
<span class="k">fi</span>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$?</span> -ne <span class="m">0</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="k">return</span> 1
<span class="k">fi</span>
<span class="k">done</span>
awk -v <span class="nv">dir1</span><span class="o">=</span><span class="nv">$arg1</span> -v <span class="nv">dir2</span><span class="o">=</span><span class="nv">$arg2</span> <span class="s1">'{</span>
<span class="s1"> if (NR==1)</span>
<span class="s1"> {</span>
<span class="s1"> printf("edit %s/%s\nvertical diffsplit %s/%s\n", dir1, $0, dir2, $0)</span>
<span class="s1"> }</span>
<span class="s1"> else</span>
<span class="s1"> {</span>
<span class="s1"> printf("tabnew %s/%s\nvertical diffsplit %s/%s\n", dir1, $0, dir2, $0)</span>
<span class="s1"> }</span>
<span class="s1"> }'</span> <span class="nv">$tmp_file</span>
<span class="o">}</span>
<span class="c1">#############################################################</span>
<span class="c1"># 获取diff info</span>
<span class="c1">#############################################################</span>
<span class="k">for</span> file in <span class="sb">`</span>find <span class="nv">$arg1</span> <span class="p">|</span> grep -v <span class="s2">"/\."</span> <span class="p">|</span> grep -v <span class="s2">"^\."</span><span class="sb">`</span>
<span class="k">do</span>
<span class="nv">file_relative_name</span><span class="o">=</span><span class="si">${</span><span class="nv">file</span><span class="p">#</span><span class="nv">$arg1</span><span class="p">/</span><span class="si">}</span>
file <span class="nv">$file</span> <span class="p">|</span> grep -Eq <span class="s2">"text"</span>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$?</span> -ne <span class="m">0</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="k">continue</span>
<span class="k">fi</span>
<span class="k">if</span> <span class="o">[</span> -f <span class="nv">$arg2</span>/<span class="nv">$file_relative_name</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
file <span class="nv">$arg2</span>/<span class="nv">$file_relative_name</span> <span class="p">|</span> grep -Eq <span class="s2">"text"</span>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$?</span> -ne <span class="m">0</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="k">continue</span>
<span class="k">fi</span>
<span class="nv">md5_1</span><span class="o">=</span><span class="sb">`</span>get_file_md5 <span class="nv">$file</span><span class="sb">`</span>
<span class="nv">md5_2</span><span class="o">=</span><span class="sb">`</span>get_file_md5 <span class="nv">$arg2</span>/<span class="nv">$file_relative_name</span><span class="sb">`</span>
<span class="k">if</span> <span class="o">[[</span> <span class="s2">"</span><span class="nv">$md5_1</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"</span><span class="nv">$md5_2</span><span class="s2">"</span> <span class="o">]]</span><span class="p">;</span><span class="k">then</span>
<span class="k">continue</span>
<span class="k">fi</span>
<span class="c1">## file not same</span>
<span class="nb">echo</span> <span class="s2">"</span><span class="nv">$file_relative_name</span><span class="s2">"</span> >> <span class="nv">$tmp_dir</span>/diff_file
<span class="k">else</span>
<span class="nb">echo</span> <span class="s2">"</span><span class="nv">$file_relative_name</span><span class="s2">"</span> >> <span class="nv">$tmp_dir</span>/A_ony_file
<span class="k">fi</span>
<span class="k">done</span>
<span class="c1">#############################################################</span>
<span class="c1"># 根据输入标签打开用vim打开文件比较diff</span>
<span class="c1">#############################################################</span>
<span class="k">if</span> <span class="o">[</span> ! -f <span class="nv">$tmp_dir</span>/diff_file <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="nb">exit</span>
<span class="k">fi</span>
show_diff <span class="nv">$tmp_dir</span>/diff_file
<span class="k">while</span> <span class="nb">true</span>
<span class="k">do</span>
<span class="nb">echo</span> -n <span class="s2">"Please choose file number list (like this:1,3-4,5):"</span>
<span class="nb">read</span> value
<span class="k">if</span> <span class="o">[[</span> <span class="s2">"</span><span class="nv">$value</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"s"</span> <span class="o">]]</span> <span class="o">||</span> <span class="o">[[</span> <span class="s2">"</span><span class="nv">$value</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"S"</span> <span class="o">]]</span><span class="p">;</span><span class="k">then</span>
show_diff <span class="nv">$tmp_dir</span>/diff_file
<span class="k">continue</span>
<span class="k">elif</span> <span class="o">[[</span> <span class="s2">"</span><span class="nv">$value</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"q"</span> <span class="o">]]</span> <span class="o">||</span> <span class="o">[[</span> <span class="s2">"</span><span class="nv">$value</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"Q"</span> <span class="o">]]</span><span class="p">;</span><span class="k">then</span>
myexit
<span class="k">elif</span> <span class="o">[[</span> <span class="s2">"</span><span class="nv">$value</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"a"</span> <span class="o">]]</span> <span class="o">||</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$value</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"A"</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="nv">value</span><span class="o">=</span><span class="s2">"1-</span>$<span class="s2">"</span>
<span class="k">fi</span>
<span class="nv">vim_script</span><span class="o">=</span><span class="sb">`</span>check_value <span class="nv">$tmp_dir</span>/diff_file <span class="s2">"</span><span class="nv">$value</span><span class="s2">"</span> 2>/dev/null<span class="sb">`</span>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$?</span> -ne <span class="m">0</span> <span class="o">]</span><span class="p">;</span><span class="k">then</span>
<span class="nb">echo</span> <span class="s2">"invalid parameter[</span><span class="nv">$value</span><span class="s2">]!"</span>
<span class="k">else</span>
vim -c <span class="s2">"</span><span class="nv">$vim_script</span><span class="s2">"</span>
<span class="k">fi</span>
<span class="k">done</span>
</pre></div>
</td></tr></table>
<hr/>
<aside>
<nav>
<ul class="articles-timeline">
<li class="previous-article">« <a href="https://chukeer.github.io/vim自动更新tag.html" title="Previous: vim自动更新tag">vim自动更新tag</a></li>
<li class="next-article"><a href="https://chukeer.github.io/一行Python代码——单词逆转.html" title="Next: 一行Python代码——单词逆转">一行Python代码——单词逆转</a> »</li>
</ul>
</nav>
</aside>
</div>
<section>
<div class="span2" style="float:right;font-size:0.9em;">
<table class="table">
<!-- <time pubdate="pubdate" datetime="2015-04-27T00:00:00+08:00"> 4 27, 2015</time> -->
<tr>
<td>Published</td>
<td><time pubdate="pubdate" datetime="2015-04-27T00:00:00+08:00">2015- 4-27</time></td>
</tr>
<tr>
<td>Category</td>
<td><a class="category-link" href="https://chukeer.github.io/categories.html#skill-ref">Skill</a></td>
</tr>
<tr>
<td>Tags</td>
<td>
<ul class="list-of-tags tags-in-article">
<li><a href="https://chukeer.github.io/tags.html#vim-ref">vim
<span>4</span>
</a></li>
</ul>
</td>
</tr>
</table>
</div>
</section>
</div>
</article>
</div>
<div class="span1"></div>
</div>
</div>
<div id="push"></div>
</div>
<footer>
<div id="footer">
<ul class="footer-content">
<li class="elegant-power">Powered by <a href="http://getpelican.com/" title="Pelican Home Page">Pelican</a>. Theme: <a href="http://oncrashreboot.com/pelican-elegant" title="Theme Elegant Home Page">Elegant</a> by <a href="http://oncrashreboot.com" title="Talha Mansoor Home Page">Talha Mansoor</a></li>
</ul>
</div>
</footer> <!--
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
-->
<script src="https://chukeer.github.io/theme/js/jquery.min.js"></script>
<script src="https://chukeer.github.io/theme/js/bootstrap.min.js"></script>
<script>
function validateForm(query)
{
return (query.length > 0);
}
</script>
<script>
$("div.article-content table").addClass("table table-hover");
</script>
</body>
<!-- Theme: Elegant built for Pelican
License : http://oncrashreboot.com/pelican-elegant -->
</html>