Skip to content
Snippets Groups Projects
Commit 868dab5b authored by Jerome Reybert's avatar Jerome Reybert
Browse files

autoload/magit/utils.vim: new function magit#utils#is_binary to test file type

parent a76323f4
No related branches found
No related tags found
No related merge requests found
...@@ -136,9 +136,7 @@ function! magit#state#add_file(mode, status, filename, depth) dict ...@@ -136,9 +136,7 @@ function! magit#state#add_file(mode, status, filename, depth) dict
let file.empty = 1 let file.empty = 1
call add(file.diff.header, 'no header') call add(file.diff.header, 'no header')
let file.diff.hunks[0].header = 'New empty file' let file.diff.hunks[0].header = 'New empty file'
elseif ( match(system("file --mime " . elseif ( magit#utils#is_binary(magit#utils#add_quotes(a:filename)))
\ magit#utils#add_quotes(a:filename)),
\ a:filename . ".*charset=binary") != -1 )
let file.binary = 1 let file.binary = 1
call add(file.diff.header, 'no header') call add(file.diff.header, 'no header')
let file.diff.hunks[0].header = 'Binary file' let file.diff.hunks[0].header = 'Binary file'
......
...@@ -33,6 +33,13 @@ function! magit#utils#git_dir() ...@@ -33,6 +33,13 @@ function! magit#utils#git_dir()
return s:magit_git_dir return s:magit_git_dir
endfunction endfunction
" s:magit#utils#is_binary: check if file is a binary file
" param[in] filename: the file path. it must quoted if it contains spaces
function! magit#utils#is_binary(filename)
return ( match(system("file --mime " . a:filename ),
\ a:filename . ".*charset=binary") != -1 )
endfunction
" s:magit_cd_cmd: plugin variable to choose lcd/cd command, 'lcd' if exists, " s:magit_cd_cmd: plugin variable to choose lcd/cd command, 'lcd' if exists,
" 'cd' otherwise " 'cd' otherwise
let s:magit_cd_cmd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' let s:magit_cd_cmd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment