Condense code: ternary operators vs. if-then-else blocks.

This commit is contained in:
Phil Runninger (mac) 2019-08-19 14:39:17 -04:00
parent 877f41e243
commit 9afab6257b

View File

@ -413,24 +413,12 @@ function! s:Path.getSortKey()
let metadata = []
for tag in g:NERDTreeSortOrder
if tag =~? '\[\[-\?timestamp\]\]'
if self.isDirectory
call add(metadata, 0)
else
call add(metadata, (tag =~ '-' ? -1 : 1) * getftime(self.str()))
endif
let metadata += [self.isDirectory ? 0 : getftime(self.str()) * (tag =~ '-' ? -1 : 1)]
elseif tag =~? '\[\[-\?size\]\]'
if self.isDirectory
call add(metadata, 0)
else
call add(metadata, (tag =~ '-' ? -1 : 1) * getfsize(self.str()))
endif
let metadata += [self.isDirectory ? 0 : getfsize(self.str()) * (tag =~ '-' ? -1 : 1)]
elseif tag =~? '\[\[extension\]\]'
if self.isDirectory
call add(metadata, '')
else
let extension = matchstr(self.getLastPathComponent(0), '[^.]\+\.\zs[^.]\+$')
call add(metadata, extension == '' ? nr2char(str2nr('0x10ffff',16)) : extension)
endif
let extension = matchstr(self.getLastPathComponent(0), '[^.]\+\.\zs[^.]\+$')
let metadata += [self.isDirectory ? '' : (extension == '' ? nr2char(str2nr('0x10ffff',16)) : extension)]
endif
endfor