Open mikepqr opened 3 years ago
This seems to do the job:
let s:DEFAULT_LS_FLAGS = "--directory --indicator-style=slash"
function! Sort(flag)
if &filetype != "dirvish" || !executable("ls")
return
endif
let dir = expand("%:h")
let cmd = printf("ls %s -%s %s/*", s:DEFAULT_LS_FLAGS, a:flag, dir)
execute printf("%%!%s", cmd)
endfunction
The only problem with it is that conceallevel is set to zero because the buffer was modified.
It would be nice to setlocal conceallevel=3
afterwards but I didn't manage to do it.
It would be nice to setlocal conceallevel=3 afterwards but I didn't manage to do it.
You could use: call timer_start(1, {-> execute('setlocal conceallevel=3')})
Using ls seems fragile. let s:DEFAULT_LS_FLAGS = "--directory --indicator-style=slash"
doesn't work on macOS (and other BSDs), for example, but this won't work at all on Windows.
vim has builtin functions for this,
getfsize({fname}) *getfsize()*
The result is a Number, which is the size in bytes of the
given file {fname}.
If {fname} is a directory, 0 is returned.
If the file {fname} can't be found, -1 is returned.
If the size of {fname} is too big to fit in a Number then -2
is returned.
getftime({fname}) *getftime()*
The result is a Number, which is the last modification time of
the given file {fname}. The value is measured as seconds
since 1st Jan 1970, and may be passed to strftime(). See also
|localtime()| and |strftime()|.
If the file {fname} can't be found -1 is returned.
getftype({fname}) *getftype()*
The result is a String, which is a description of the kind of
file of the given file {fname}.
If {fname} does not exist an empty string is returned.
Here is a table over different kinds of files and their
results:
Is there a way to sort the list by item attributes other than the name such as modification time (the one I'm interested in), size, etc.?