diff options
author | Moritz Poldrack <git@moritz.sh> | 2022-12-20 09:59:13 +0100 |
---|---|---|
committer | Moritz Poldrack <git@moritz.sh> | 2022-12-20 10:51:47 +0100 |
commit | 466888da4776ec9e67d9765e2465e295e4d74060 (patch) | |
tree | fba8d66f8a44a9cc1fac9b664a116d199836246b /commands/compose | |
parent | 060fbb04a436ce4ec0937384e177aa16524332a2 (diff) | |
download | aerc-466888da4776ec9e67d9765e2465e295e4d74060.tar.gz |
attach: don't glob hidden files
Most of the time it is not wanted to attach hidden files, but by default
globbing does include hidden files.
Add a small check that removes hidden files from the results if they are
not explicitly globbed for or inside a hidden directory.
Implements: https://todo.sr.ht/~rjarry/aerc/83
Signed-off-by: Moritz Poldrack <git@moritz.sh>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Diffstat (limited to 'commands/compose')
-rw-r--r-- | commands/compose/attach.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/commands/compose/attach.go b/commands/compose/attach.go index 7e50ea85..520fc6f7 100644 --- a/commands/compose/attach.go +++ b/commands/compose/attach.go @@ -59,6 +59,19 @@ func (a Attach) addPath(aerc *widgets.Aerc, path string) error { attachments = []string{path} } + if !strings.HasPrefix(path, ".") && !strings.Contains(path, "/.") { + log.Debugf("removing hidden files from glob results") + for i := len(attachments) - 1; i >= 0; i-- { + if strings.HasPrefix(filepath.Base(attachments[i]), ".") { + if i == len(attachments)-1 { + attachments = attachments[:i] + continue + } + attachments = append(attachments[:i], attachments[i+1:]...) + } + } + } + composer, _ := aerc.SelectedTabContent().(*widgets.Composer) for _, attach := range attachments { log.Debugf("attaching '%s'", attach) |