Skip to content

Commit 2415842

Browse files
Use shellslash if available and fix arglist highlighting.
1 parent ea8cda4 commit 2415842

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

plugin/dirvish_git.vim

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ let s:dirvish_git_highlight_groups = {
2727
\ 'Unknown' : 'DirvishGitModified'
2828
\ }
2929

30+
let s:sep = exists('+shellslash') && !&shellslash ? '\' : '/'
3031
let s:git_files = {}
3132

3233
function! dirvish_git#init() abort
@@ -55,18 +56,18 @@ function! dirvish_git#init() abort
5556
let l:them = l:data[2]
5657
let l:file = l:data[3]
5758

58-
if index(argv(), l:file) > -1
59+
if s:is_in_arglist(l:file)
5960
continue
6061
endif
6162

6263
let l:file = fnamemodify(l:file, ':p')
63-
let l:file = matchstr(l:file, escape(l:current_dir.'[^/]*/\?', './'))
64+
let l:file = matchstr(l:file, escape(l:current_dir.'[^'.s:sep.']*'.s:sep.'\?', '.'.s:sep))
6465

6566
if index(values(s:git_files), l:file) > -1
6667
continue
6768
endif
6869

69-
let l:line_number = search(escape(l:file, './'), 'n')
70+
let l:line_number = search(escape(l:file, '.'.s:sep), 'n')
7071
let s:git_files[l:line_number] = l:file
7172

7273
if isdirectory(l:file)
@@ -114,9 +115,9 @@ function! s:get_highlight_group(us, them, is_directory) abort
114115
endfunction
115116

116117
function! s:highlight_file(dir, file_name, us, them, is_directory) abort
117-
let l:file_rgx = escape(printf('\(%s\)\@<=/%s', a:dir, a:file_name), './')
118-
let l:dir_rgx = escape(printf('%s\(/%s\)\@=', a:dir, a:file_name), './')
119-
let l:slash_rgx = escape(printf('\(%s\)\@<=/\(%s\)\@=', a:dir, a:file_name), './')
118+
let l:file_rgx = escape(printf('\(%s\)\@<=%s%s', a:dir, s:sep, a:file_name), './')
119+
let l:dir_rgx = escape(printf('%s\(%s%s\)\@=', a:dir, s:sep, a:file_name), './')
120+
let l:slash_rgx = escape(printf('\(%s\)\@<=%s\(%s\)\@=', a:dir, s:sep, a:file_name), './')
120121

121122
silent exe 'syn match DirvishGitDir "'.l:dir_rgx.'" conceal cchar='.s:get_indicator(a:us, a:them)
122123
silent exe 'syn match '.s:get_highlight_group(a:us, a:them, a:is_directory).' "'.l:file_rgx.'" contains=DirvishGitSlash'
@@ -138,14 +139,27 @@ function! s:setup_highlighting() abort
138139
silent exe 'hi default DirvishGitUntracked guifg=NONE guibg=NONE gui=NONE cterm=NONE ctermfg=NONE ctermbg=NONE'
139140
endfunction
140141

142+
function s:is_in_arglist(file) abort
143+
let l:file = fnamemodify(a:file, ':p')
144+
let l:cwd = printf('%s%s', getcwd(), s:sep)
145+
for l:arg in argv()
146+
if l:arg ==# l:cwd
147+
continue
148+
endif
149+
if l:file =~? l:arg
150+
return 1
151+
endif
152+
endfor
153+
return 0
154+
endfunction
155+
141156
function! dirvish_git#jump_to_next_file() abort
142157
if len(s:git_files) <=? 0
143158
return
144159
endif
145160

146161
let l:current_line = line('.')
147162
let l:git_files_line_number = sort(keys(s:git_files), 'N')
148-
echo l:git_files_line_number
149163

150164
for l:line in l:git_files_line_number
151165
if l:line > l:current_line
@@ -175,7 +189,7 @@ endfunction
175189

176190
function! dirvish_git#reload() abort
177191
if &filetype ==? 'dirvish' && len(s:git_files) > 0
178-
Dirvish %
192+
call feedkeys('R')
179193
endif
180194
endfunction
181195

0 commit comments

Comments
 (0)