aboutsummaryrefslogblamecommitdiffstats
path: root/config/openers.go
blob: e246ea64fcce50f5db1dc6fb9098e2e2ee13c6f3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11


              
             

                 
                                    



                                 





                     

                                         




                                                  


                                                                      

                                  



                                                                                      



                 
                                                       

                  
package config

import (
	"fmt"
	"strings"

	"git.sr.ht/~rjarry/aerc/log"
	"github.com/go-ini/ini"
	"github.com/google/shlex"
)

type Opener struct {
	Mime string
	Args []string
}

var Openers []Opener

func parseOpeners(file *ini.File) error {
	openers, err := file.GetSection("openers")
	if err != nil {
		goto out
	}

	for _, key := range openers.Keys() {
		mime := strings.ToLower(key.Name())
		if args, err := shlex.Split(key.Value()); err != nil {
			return err
		} else {
			if len(args) == 0 {
				return fmt.Errorf("opener command empty for %s", mime)
			}
			Openers = append(Openers, Opener{Mime: mime, Args: args})
		}
	}

out:
	log.Debugf("aerc.conf: [openers] %#v", Openers)
	return nil
}