Visual Filters, extended patterns and more in donnatella

Freshly pushed to the branch next on donnatella's github are a few commits, some fixes and other improvements here and there of course, and a few things worth spending a few more words about.

First of all, you could use patterns in a few places in donna, such as when filtering via names (or any text property) or to define arrangements. A pattern was a string that could contain wildchars in a glob-like manner. They've now become a bit more powerful...

Patterns are more than just patterns

A pattern is now a string that can start with one of the following, to specify which mode to use :

  • a double quote (") for glob-like pattern mode, the only thing originally supported: the given string can use * and ? as wildchars with similar semantics as the standard glob() function
  • a single-quote (') for search mode: the given string will be searched (case sensitive) in the matched against string
  • a caret (^) for begin mode: the matched against string must begin with the given string to match
  • a dollar sign ($) for end mode: the matched against string must end with the given string to match
  • a tilde sign (~) for case-insensitive matching mode: the matched against string and the given string must be the same (case insensitively)
  • an equal sign (=) for case-sensitive matching mode: the matched against string and the given string must be the exact same
  • a greater than sign (>) for regex mode: the given string must be Perl-compatible regular expression to be matched against

If the string doesn't start with any of those, search mode will be used unless there is at least one wildchar, then pattern mode is used.

Additionally, if the string first starts with a pipe character (|) then any other pipe character will be used as a separator (i.e. it cannot be used in any pattern definition), allowing you to specify more than one possible patterns to match.

Note that each time the prefix rule apply, e.g. to match strings that end either with "foo" or "bar" use |$foo|$bar Of course you can use different types, e.g: |this file|*.pdf|>report [0-9]{4}\.xml

This makes every feature using patterns much more powerfull than before. One thing worth mentionning though, is that the columntype name used to support using the pipe character to specify more than one pattern. It was a oddity (in that it was alone to support it), but now that this is part of the general pattern syntax, a change of syntax is in order: the pattern string must start with a pipe character, to enable it.

Filter by node type

Columntype name only allowed to filter using patterns, matched against the node's name. You can now also filter by node type, using + or - followed by either c (or d) to match only containers (directories), or i (or f) to match only items (files).

So using +f will match only files, just like -d would. So if you're looking to filter only directories modified yesterday, you could use:

name:"+d" and time:A1d

Visual Filters

Another addition is that of visual filters (VF). Filtering capabilities have been part of donna from day one, but until now you couldn't use them to filter what is visible on list: now you can!

Two new commands have been added to do so: tv_set_visual_filter() to set a visual filter, and tv_get_visual_filter() to get the current one. Unsetting a VF is simply done by not specifying a new one (or using an empty string as VF).

An option toggle also allows to unset the VF if trying to set a VF that is already set.

How to use some VF

Some default keys allow you to use VF easily: pressing f followed by a letter will apply said filter, which is simply defined as a configuration option under category "filters" For example, "fv" to only show videos, "fi" for images, "ft" for rows modified today, "fw" for ones modified this week...

And using F instead will work the same, but allowing you to edit the filter before applying it. As a nice trick, keeping filters/f an option set to an empty string will allow to press "ff" to unset any current VF.

Dynamic VFs

Some other nice things can be done, for example typing a size followed by either lesser than (<) or greater than (>) will filter by the specified size (in MiB).

Pressing q will only show rows modified today. Of course, you can prefix it with a number of days, e.g. 1q to show rows from yesterday, 2q from two days ago, etc. You can even prefix this with & followed by a time unit, e.g. &Vq for modified this week, &V2q for two weeks ago, etc

Lastly, using Q works similarly, but where q resolves to time:A<NB><UNIT> using Q will resolves to time:A<=<NB><UNIT> so e.g. &V2Q means modified anytime from two weeks ago (i.e. includes last week and this week as well).

Those are only examples of course, since as always, you can define things how you like/want/need them to be. (And don't hesitate to share your cool tricks!)

Filter files only

One last note: if you only ever want your VF to apply to files, but mean for all directories to always all remain visible, no need to specify it on each & every filter you use: simply set treeview option vf_items_only to true.

Better status info

Some changes in the possibilities of the status area from a treeview. A few variables were added: %f for the focused row, %F for the current VF, %h and %H for the number/size of hidden rows respectively.

All of "avhsF" also supports an extra (in between brackets), which is itself a string parsed the same way and supporting the same variables (If you need recursion, any backslash or closing braquet must be escaped via backslash).

The parsed string will then be shown instead of what the variable usually resolves to. However, there's a twist:

  • for %F it will only be shown when a VF is set (else resolves to nothing/empty string)
  • for the others, the string will also be splitted using comma as separator (if you need to use commas, you then need to use %,), so you can specify up to 3 strings.

With only 1 string, it will be shown unless the reference (i.e. the number of items the variable refers to) is zero. With 2 strings, nothing is shown if the reference is zero, the first one is shown if it is one, else the second one is shown. Lastly, with 3 strings, the first one is shown is reference is zero, the second one if it's one, else the last one is shown.

%a behaves a little differently, in that instead of not showing anything (or the first of the 3 specified strings) when the reference (i.e. number of all rows) is zero, it does so when it is the same as the number of visible rows. This is to make it easy to show e.g. "23 rows" when all are visible, and "23/42 rows" when some are hidden, using: %{%v/}a%a rows

And option key_modes_colors was renamed to simply colors and isn't a boolean anymore, but can take values "off", "keys" or "vf" The later case being used when a VF is set.

Finally, the same variables are supported in option format_tooltip, used for the tooltip of the statusbar area (no color support there).

Updating your config to benefit from all of this

Now, there's still work to do when it comes to upgrades in donna. Specifically, there isn't currently a way to update/import new defaults, so that is a manual operation. Archers, think of this as some king of .pacnew handling! ;)

Here's the patch to update your donnatella.conf (from last time) :

  1. diff --git a/misc/donnatella.conf b/misc/donnatella.conf
  2. index d45fd98..e58b10b 100644
  3. --- a/misc/donnatella.conf
  4. +++ b/misc/donnatella.conf
  5. @@ -92,8 +92,11 @@ expand=false
  6.  [statusbar/active]
  7.  source=:active
  8.  expand=false
  9. -format=%v/%a files (%V) %N
  10. +{% raw %}format=%{%s/}s%{no rows,1 row,%v rows}v(%{%S / }s%V)%{ %h hidden (%H)}h
  11. +{% endraw %}format_tooltip=%{Current VF: %F}F
  12.  size_format=%R
  13. +colors:tree-st-colors=vf
  14. +foreground=blue
  16.  [statusbar/log]
  17.  source=:app
  18. @@ -112,7 +115,7 @@ source=:focused
  19.  format=%o %K
  20.  width=100
  21.  expand=false
  22. -key_modes_colors=true
  23. +colors:tree-st-colors=keys
  24.  key_mode_select_background-rgba=rgba(0,42,200,0.8)
  25.  key_mode_select_foreground=white
  27. @@ -191,6 +194,7 @@ sort_groups:sg=first
  28.  select_highlight:highlight=column-underline
  29.  focusing_click=true
  30.  goto_item_set:tree-set=scroll,focus
  31. +vf_items_only=false
  32.  history_max=100
  33.  context_menu_menus=context
  34.  context_menu=@go:tree,marks,-,add_to_tree<add_as_root>,-,!new_nodes,-,@register,-,@selection,-,column_edit<!column_edit>,-,:refresh<@refresh>
  35. @@ -201,7 +205,7 @@ context_menu_colheader=columns<!columns>,-,:sort_order<!sort_order>,:second_sort
  36.  # some color filters
  38.  [defaults/lists/arrangement/color_filters/]
  39. -filter=*.tar.*|*.tgz|*.zip|*.rar
  40. +filter=|*.tar.*|*.tgz|*.zip|*.rar
  41.  column=name
  42.  foreground=green
  44. @@ -775,6 +779,36 @@ trigger=command:node_trigger(@ask_text(Enter FL to trigger))
  45.  [key_modes/donna/key_slash]
  46.  trigger=command:tv_start_interactive_search (%o)
  48. +# Visual Filters
  49. +[key_modes/donna/key_f]
  50. +type:key=spec
  51. +spec:spec=lower,upper
  52. +trigger=command:tv_set_visual_filter (%o, @config_get_string (filters/%k), 1)
  53. +[key_modes/donna/key_F]
  54. +type:key=spec
  55. +spec:spec=lower,upper
  56. +trigger=command:tv_set_visual_filter (%o, @config_set_string (filters/%k, @ask_text (Enter filter %k,,@config_try_get_string (filters/%k, @tv_get_visual_filter (%o)))), 1)
  57. +
  58. +# VF: by age
  59. +[key_modes/donna/key_ampersand]
  60. +type:key=combine
  61. +spec:spec=custom
  62. +custom_chars=HMSdmVY
  63. +combine=age_unit
  64. +[key_modes/donna/key_q]
  65. +combine=age_unit
  66. +trigger=command:tv_set_visual_filter (%o, time:A%m%c)
  67. +[key_modes/donna/key_Q]
  68. +combine=age_unit
  69. +trigger=command:tv_set_visual_filter (%o, time:A<=%m%c)
  70. +
  71. +# VF: by size
  72. +[key_modes/donna/key_less]
  73. +trigger=command:tv_set_visual_filter (%o, size:<=%mM)
  74. +[key_modes/donna/key_greater]
  75. +trigger=command:tv_set_visual_filter (%o, size:>=%mM)
  76. +
  77. +
  78.  # F2 to rename
  79.  [key_modes/donna/key_F2]
  80.  trigger=command:tv_column_edit (%o, %n, name)
  81. @@ -1155,4 +1189,25 @@ node=config:/
  82.  box=box-orange
  85. +#
  86. +#       FILTERS
  87. +#
  88. +
  89. +[filters]
  90. +# used to unset current VF (via ff)
  91. +f=
  92. +# today
  93. +t=time:A0
  94. +# yesterday
  95. +y=time:A1d
  96. +# this week
  97. +w=time:A0V
  98. +# videos
  99. +v=desc:* video
  100. +# images
  101. +i=desc:* image
  102. +# archives
  103. +a=desc:* archive*
  104. +
  105. +
  106.  # EOF

Where to get it?

For Arch Linux users, you can use donnatella-git in the AUR to easilly get it. Or simply clone the git repo from github and compile things yourself.

For a a complete list of all changes/bug fixes please refer to the git log.

And in case you read all that and are wondering what donnatella is, or are looking for more information, download links, etc please refer to donnatella.

As always, bug reports, suggestions or any other form of constructive criticism is very much welcome. You can open issues on github, use the thread on Arch Linux forums, or simply email me.

Top of Page