Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort by modification time, size, etc. #205

Open
mikepqr opened this issue Nov 14, 2020 · 4 comments
Open

Sort by modification time, size, etc. #205

mikepqr opened this issue Nov 14, 2020 · 4 comments

Comments

@mikepqr
Copy link

mikepqr commented Nov 14, 2020

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

@phelipetls
Copy link

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.

@davidsierradz
Copy link

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

@mikepqr
Copy link
Author

mikepqr commented Mar 23, 2021

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.

@justinmk
Copy link
Owner

justinmk commented Jul 8, 2021

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants