summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2022-12-20 09:59:13 +0100
committerMoritz Poldrack <git@moritz.sh>2022-12-20 10:51:47 +0100
commit466888da4776ec9e67d9765e2465e295e4d74060 (patch)
treefba8d66f8a44a9cc1fac9b664a116d199836246b
parent060fbb04a436ce4ec0937384e177aa16524332a2 (diff)
downloadaerc-466888da4776ec9e67d9765e2465e295e4d74060.tar.gz
aerc-466888da4776ec9e67d9765e2465e295e4d74060.zip
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>
-rw-r--r--commands/compose/attach.go13
-rw-r--r--commands/util.go13
2 files changed, 26 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)
diff --git a/commands/util.go b/commands/util.go
index fe0b2756..8b7060ec 100644
--- a/commands/util.go
+++ b/commands/util.go
@@ -97,6 +97,19 @@ func CompletePath(path string) []string {
return nil
}
+ if !strings.HasPrefix(path, ".") && !strings.Contains(path, "/.") {
+ log.Debugf("removing hidden files from glob results")
+ for i := len(matches) - 1; i >= 0; i-- {
+ if strings.HasPrefix(filepath.Base(matches[i]), ".") {
+ if i == len(matches)-1 {
+ matches = matches[:i]
+ continue
+ }
+ matches = append(matches[:i], matches[i+1:]...)
+ }
+ }
+ }
+
for i, m := range matches {
if isDir(m) {
matches[i] = m + "/"