Skip to content

Commit

Permalink
vifm.mkd: most recently committed files!
Browse files Browse the repository at this point in the history
  • Loading branch information
sitaramc committed Apr 3, 2019
1 parent 46f7a5a commit b339e5c
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions vifm.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,20 @@ the author's own vifmrc!)

* **custom views** (as vifm calls them) allow you to load a filelist
generated by a program. I've *always* struggled with tasks like finding
the most recent 10 files, the largest 20 files, or whatever, because I
always had to get out of the file manager.
the most recent files, most recently committed files, largest files, or
whatever, because I always had to get out of the file manager.

Not anymore! See section on "finding files" later.

A quick note about the "most recently committed files": by itself that's
not such a big deal, but, combined with the previous feature ("git log" as
preview), it is a good contrast to `gitk` (or `:GV` in vim) -- it is a
view from the other direction, in a way (files -> commits, as opposed to
commits -> files). Time will tell how useful it really is, but I can
certainly say that I know of no other file manager that lets me do this at
all, leave alone so painlessly and intuitively, and that's the important
part here.

* **sorting display**: whatever field you choose to sort by, that is the
field you will see next to the filename!

Expand Down Expand Up @@ -412,29 +421,28 @@ view.

### finding the latest, or largest, files

I mentioned this up at the top, but here's how you get the largest N or newest
N files.
I mentioned this up at the top, but here's how you get the largest N, newest
N, or most recently committed N, files.

command! xm :set viewcolumns=*{name}..,24{mtime}| InternalXM %a
command! xs :set viewcolumns=*{name}..,8{size}| InternalXS %a
command! InternalXM find -type f -print0 | xargs -0 ls -tr | tail -%a | tac %U
command! InternalXS find -type f -print0 | xargs -0 ls -Sr | tail -%a | tac %U
command! xc :set viewcolumns=*{name}..,24{mtime}| zzzInternalXC %a
command! xm :set viewcolumns=*{name}..,24{mtime}| zzzInternalXM %a
command! xs :set viewcolumns=*{name}..,8{size}| zzzInternalXS %a
command! zzzInternalXC git log --name-only --format=%%n | perl -lne 'print if /./ and -f and not $seen{$_}++' | head -%a %U
command! zzzInternalXM find -type f -print0 | xargs -0 ls -tr | tail -%a | tac %U
command! zzzInternalXS find -type f -print0 | xargs -0 ls -Sr | tail -%a | tac %U
" the 'zzz' is so they will show up last when I hit ':<Tab>'
" also, notice the %% in the format paramater in zzzInternalXC

You run this by typing `:xs 10` to get the largest 10 files (s for 'size'),
or, say, `:xm 20` to get the newest 20 files (m for 'mtime'), and they will be
loaded in a **custom view**.
You run this by typing `:xc 10` to get the 10 most recently committed files (c
for 'commit'), and they will be loaded in a **custom view**. Similarly s is
for size and m is for mtime.

The [`%a`][pc_a] is replaced by the 10 or 20 or whatever you supplied.
However, the [`%U`][pc_U] is what makes all this work: it basically takes the
command output and creates a "custom view" out of it! (I use `%U` instead of
`%u` because I don't want vifm to needlessly sort it on some other key, when
it's already sorted!)

You can make some adjustments to the options supplied to `ls` if you want,
say, *oldest* files, or *smallest* files etc. (Do not be tempted to convert
the `tail` to a `head`; that often results in a pipe error. Not harmful but
ugly and disconcerting.)

[sf]:https://github.com/sitaramc/active-aliases/blob/master/examples/sf "https://github.com/sitaramc/active-aliases/blob/master/examples/sf"
[fprg]:https://vifm.info/vimdoc.shtml#vifm-%27findprg%27 "https://vifm.info/vimdoc.shtml#vifm-%27findprg%27"
[lprg]:https://vifm.info/vimdoc.shtml#vifm-%27locateprg%27 "https://vifm.info/vimdoc.shtml#vifm-%27locateprg%27"
Expand Down

0 comments on commit b339e5c

Please sign in to comment.