File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ " ======================================================================
2
+ "
3
+ " shebang.vim -
4
+ "
5
+ " Created by skywind on 2022/01/12
6
+ " Last Modified: 2022/01/12 22:30:25
7
+ "
8
+ " ======================================================================
9
+
10
+ function ! asyncrun#program#shebang#translate (opts)
11
+ let cmd = asyncrun#utils#strip (a: opts .cmd)
12
+ if cmd == ' '
13
+ return ' echo empty command'
14
+ endif
15
+ if cmd = ~ ' ^".*"$'
16
+ let cmd = asyncrun#utils#strip (strpart (cmd, 1 , len (cmd) - 2 ))
17
+ endif
18
+ if cmd = ~ ' ^\'' .*\'' $'
19
+ let cmd = asyncrun#utils#strip (strpart (cmd, 1 , len (cmd) - 2 ))
20
+ endif
21
+ if filereadable (cmd) == 0
22
+ return ' echo file not find: ' . cmd
23
+ endif
24
+ let textlist = readfile (cmd, ' ' , 20 )
25
+ let shebang = ' '
26
+ for text in textlist
27
+ let text = asyncrun#utils#strip (text)
28
+ if text = ~ ' ^#'
29
+ let text = asyncrun#utils#strip (strpart (text, 1 ))
30
+ if text = ~ ' ^!'
31
+ let shebang = asyncrun#utils#strip (strpart (text, 1 ))
32
+ break
33
+ endif
34
+ endif
35
+ endfor
36
+ if shebang == ' '
37
+ return ' echo shebang not find in: ' . cmd
38
+ endif
39
+ return shebang . ' "' . cmd . ' "'
40
+ endfunc
41
+
42
+
Original file line number Diff line number Diff line change @@ -22,6 +22,23 @@ function! asyncrun#utils#errmsg(msg)
22
22
endfunc
23
23
24
24
25
+ " ----------------------------------------------------------------------
26
+ " strip string
27
+ " ----------------------------------------------------------------------
28
+ function ! asyncrun#utils#strip (text)
29
+ return substitute (a: text , ' ^\s*\(.\{-}\)\s*$' , ' \1' , ' ' )
30
+ endfunc
31
+
32
+
33
+ " ----------------------------------------------------------------------
34
+ " Replace string
35
+ " ----------------------------------------------------------------------
36
+ function ! asyncrun#utils#replace (text, old, new )
37
+ let l: data = split (a: text , a: old , 1 )
38
+ return join (l: data , a: new )
39
+ endfunc
40
+
41
+
25
42
" ----------------------------------------------------------------------
26
43
" display require message
27
44
" ----------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments