From 467ae8ef6f26f74431e131441529bcd6d567df63 Mon Sep 17 00:00:00 2001 From: delphinus Date: Wed, 23 Dec 2015 08:02:26 +0900 Subject: [PATCH 1/2] Detect Darwin with lighter method --- plugin/webdevicons.vim | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/plugin/webdevicons.vim b/plugin/webdevicons.vim index 3aef14d..19b00e2 100644 --- a/plugin/webdevicons.vim +++ b/plugin/webdevicons.vim @@ -4,7 +4,6 @@ " License: see LICENSE let s:version = '0.7.1' -let s:operatingsystem = system("uname -s") " standard fix/safety: line continuation (avoiding side effects) {{{1 "======================================================================== @@ -137,6 +136,36 @@ endif " local functions {{{2 "======================================================================== +" scope: local +function s:isDarwin() + if exists('s:is_darwin') + return s:is_darwin + endif + + if exists('g:WebDevIconsOS') + let s:is_darwin = g:WebDevIconsOS ==? 'Darwin' + return s:is_darwin + endif + + if has('macunix') + let s:is_darwin = 1 + return s:is_darwin + endif + + if ! has('unix') + let s:is_darwin = 0 + return s:is_darwin + endif + + if system('uname -s') ==# "Darwin\n" + let s:is_darwin = 1 + else + let s:is_darwin = 0 + endif + + return s:is_darwin +endfunction + " scope: local function! s:strip(input) return substitute(a:input, '^\s*\(.\{-}\)\s*$', '\1', '') @@ -534,7 +563,7 @@ function! WebDevIconsGetFileFormatSymbol(...) if &fileformat == "dos" let fileformat = "" elseif &fileformat == "unix" - if s:operatingsystem == "Darwin\n" + if s:isDarwin() let fileformat = "" else let fileformat = "" From 46a928bf3ccb4e1523b9d1d607f026638c2eb717 Mon Sep 17 00:00:00 2001 From: delphinus Date: Mon, 8 Feb 2016 08:43:05 +0900 Subject: [PATCH 2/2] Add readme for `g:WebDevIconsOS` --- readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/readme.md b/readme.md index 840e4f2..3ecb459 100644 --- a/readme.md +++ b/readme.md @@ -413,6 +413,12 @@ let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols = {} " needed let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['myext'] = 'ƛ' ``` +* specify OS to decide an icon for unix fileformat (_not_ defined by default) + - this is useful for avoiding unnecessary `system()` call. you might see [#135](https://github.com/ryanoasis/vim-devicons/pull/135) to know logic further. + ```vim +let g:WebDevIconsOS = 'Darwin' + ``` + ## Lightline Setup To add the appropriate icon to [lightline](https://github.com/itchyny/lightline.vim), call the function `WebDevIconsGetFileTypeSymbol()` and/or `WebDevIconsGetFileFormatSymbol()` in your `.vimrc`. For example, you could set your sections to: