vim-dirvish icon indicating copy to clipboard operation
vim-dirvish copied to clipboard

Sort by modification time, size, etc.

Open mikepqr opened this issue 5 years ago • 4 comments

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.?

mikepqr avatar Nov 14 '20 06:11 mikepqr

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.

phelipetls avatar Jan 30 '21 14:01 phelipetls

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')})

davidsierradz avatar Mar 23 '21 20:03 davidsierradz

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.

mikepqr avatar Mar 23 '21 22:03 mikepqr

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:

justinmk avatar Jul 08 '21 00:07 justinmk