aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Xu <dxu@dxuuu.xyz>2019-08-16 00:11:37 -0700
committerDrew DeVault <sir@cmpwn.com>2019-08-19 15:22:59 +0900
commit9fd6054ca1a99205d2abb6408ece747d2eddaae7 (patch)
tree00e9e394ddd7d486797aefef065b450692b7cbec
parentb47143ccc7fdb54e62d8536414a5cf38852eae40 (diff)
Support regex filters for folders
It's nice to be able to filter the folders displayed in the side bar. Basic string matching can get verbose with enough folders whitelisted. Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
-rw-r--r--doc/aerc-config.5.scd3
-rw-r--r--widgets/dirlist.go12
2 files changed, 13 insertions, 2 deletions
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 995fe75..690b49a 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -225,7 +225,8 @@ Note that many of these configuration options are written for you, such as
Default: INBOX
*folders*
- Specifies the list of folders to display in the sidebar.
+ Specifies the comma separated list of folders to display in the sidebar.
+ Supports regex patterns.
Default: all folders
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index b0807ae..c84f839 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -2,6 +2,7 @@ package widgets
import (
"log"
+ "regexp"
"sort"
"github.com/gdamore/tcell"
@@ -159,6 +160,15 @@ func (dirlist *DirectoryList) Prev() {
dirlist.NextPrev(-1)
}
+func folderMatches(folder string, pattern string) bool {
+ r, err := regexp.Compile(pattern)
+ if err != nil {
+ return false
+ }
+
+ return r.Match([]byte(folder))
+}
+
// filterDirsByFoldersConfig sets dirlist.dirs to the filtered subset of the
// dirstore, based on the AccountConfig.Folders option
func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
@@ -170,7 +180,7 @@ func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
var filtered []string
for _, folder := range dirlist.dirs {
for _, cfgfolder := range dirlist.acctConf.Folders {
- if folder == cfgfolder {
+ if folderMatches(folder, cfgfolder) {
filtered = append(filtered, folder)
break
}