From 8223e02e50343c77d45e5ddebc6cf26aa6320641 Mon Sep 17 00:00:00 2001 From: Gurkengewuerz Date: Mon, 4 Nov 2019 21:19:05 +0100 Subject: [PATCH] change filepath to script --- gpgit.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gpgit.go b/gpgit.go index 21eb295..2317555 100644 --- a/gpgit.go +++ b/gpgit.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "log" "os" + "path/filepath" "regexp" "strings" @@ -62,7 +63,7 @@ func isPGPMessage(msg string) (bool, error) { return matched, err } -func isEncrypted(mail *message.Entity) (bool) { +func isEncrypted(mail *message.Entity) bool { t, _, _ := mail.Header.ContentType() if strings.ToLower(t) == "multipart/encrypted" { return true @@ -131,6 +132,18 @@ func encryptEML(eml string, armoredKeyRing *string) { } func main() { + dir, err := filepath.Abs(filepath.Dir(os.Args[0])) + if err != nil { + log.Fatal(err) + } + + if !strings.HasPrefix(dir, os.TempDir()) { + err = os.Chdir(dir) + if err != nil { + log.Fatal(err) + } + } + cfg, err := ini.Load("config.ini") if err != nil { fmt.Printf("Fail to read file: %v", err)