aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-08-23 21:36:23 +0200
committerRobin Jarry <robin@jarry.cc>2023-08-27 18:44:12 +0200
commita5bc7ccf0cae608ac1e72ab4c9ebe5596eb8c988 (patch)
treebe2e5f55fc21980489dca61947ea6b9819853ec3 /widgets
parentfff16640ad7cd8c4b73187fbce10f2aa558701be (diff)
downloadaerc-a5bc7ccf0cae608ac1e72ab4c9ebe5596eb8c988.tar.gz
xdg: get rid of deprecated dependencies
github.com/mitchellh/go-homedir has not received any update since 2019. The last release of github.com/kyoh86/xdg was in 2020 and it has been marked as deprecated by its author. Replace these with internal functions. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'widgets')
-rw-r--r--widgets/account-wizard.go34
-rw-r--r--widgets/compose.go7
2 files changed, 11 insertions, 30 deletions
diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go
index b0615ef8..7bb61079 100644
--- a/widgets/account-wizard.go
+++ b/widgets/account-wizard.go
@@ -7,7 +7,6 @@ import (
"net/url"
"os"
"os/exec"
- "path"
"regexp"
"strconv"
"strings"
@@ -16,13 +15,12 @@ import (
"github.com/emersion/go-message/mail"
"github.com/gdamore/tcell/v2"
"github.com/go-ini/ini"
- "github.com/kyoh86/xdg"
- "github.com/mitchellh/go-homedir"
"golang.org/x/sys/unix"
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib/format"
"git.sr.ht/~rjarry/aerc/lib/ui"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
"git.sr.ht/~rjarry/aerc/log"
)
@@ -356,7 +354,7 @@ Make sure to review the contents of this file and read the
aerc-accounts(5) man page for guidance and further tweaking.
To add another account in the future, run ':new-account'.
-`, tildeHome(path.Join(xdg.ConfigHome(), "aerc"))),
+`, xdg.TildeHome(xdg.ConfigPath("aerc"))),
&wizard.complete,
)
complete.AddField(
@@ -413,7 +411,7 @@ func (wizard *AccountWizard) errorFor(d ui.Interactive, err error) {
}
func (wizard *AccountWizard) finish(tutorial bool) {
- accountsConf := path.Join(xdg.ConfigHome(), "aerc", "accounts.conf")
+ accountsConf := xdg.ConfigPath("aerc", "accounts.conf")
// Validation
if wizard.accountName.String() == "" {
@@ -439,10 +437,7 @@ func (wizard *AccountWizard) finish(tutorial bool) {
}
switch wizard.sourceProtocol.Selected() {
case MAILDIR, MAILDIRPP, NOTMUCH:
- path := wizard.sourceServer.String()
- if p, err := homedir.Expand(path); err == nil {
- path = p
- }
+ path := xdg.ExpandHome(wizard.sourceServer.String())
s, err := os.Stat(path)
if err == nil && !s.IsDir() {
err = fmt.Errorf("%s: Not a directory", s.Name())
@@ -456,10 +451,7 @@ func (wizard *AccountWizard) finish(tutorial bool) {
}
}
if wizard.outgoingProtocol.Selected() == SENDMAIL {
- path := wizard.outgoingServer.String()
- if p, err := homedir.Expand(path); err == nil {
- path = p
- }
+ path := xdg.ExpandHome(wizard.outgoingServer.String())
s, err := os.Stat(path)
if err == nil && !s.Mode().IsRegular() {
err = fmt.Errorf("%s: Not a regular file", s.Name())
@@ -510,7 +502,7 @@ func (wizard *AccountWizard) finish(tutorial bool) {
out, err := cmd.Output()
if err == nil {
root := strings.TrimSpace(string(out))
- _, _ = sec.NewKey("maildir-store", tildeHome(root))
+ _, _ = sec.NewKey("maildir-store", xdg.TildeHome(root))
}
querymap := ini.Empty()
def := querymap.Section("")
@@ -526,7 +518,7 @@ func (wizard *AccountWizard) finish(tutorial bool) {
_, _ = def.NewKey("INBOX", "tag:inbox and not tag:archived")
}
if !wizard.temporary {
- qmapPath := path.Join(xdg.ConfigHome(), "aerc",
+ qmapPath := xdg.ConfigPath("aerc",
wizard.accountName.String()+".qmap")
f, err := os.OpenFile(qmapPath, os.O_WRONLY|os.O_CREATE, 0o600)
if err != nil {
@@ -538,7 +530,7 @@ func (wizard *AccountWizard) finish(tutorial bool) {
wizard.errorFor(nil, err)
return
}
- _, _ = sec.NewKey("query-map", tildeHome(qmapPath))
+ _, _ = sec.NewKey("query-map", xdg.TildeHome(qmapPath))
}
}
@@ -866,7 +858,7 @@ func (wizard *AccountWizard) autofill() {
out, err := cmd.Output()
if err == nil {
db := strings.TrimSpace(string(out))
- wizard.sourceServer.Set(tildeHome(db))
+ wizard.sourceServer.Set(xdg.TildeHome(db))
} else {
wizard.sourceServer.Set("~/mail")
}
@@ -897,11 +889,3 @@ func (wizard *AccountWizard) autofill() {
}
}
}
-
-func tildeHome(path string) string {
- home, err := homedir.Dir()
- if err == nil && home != "" && strings.HasPrefix(path, home) {
- path = "~" + strings.TrimPrefix(path, home)
- }
- return path
-}
diff --git a/widgets/compose.go b/widgets/compose.go
index 5ad67fd3..f682fe5c 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -18,7 +18,6 @@ import (
"github.com/emersion/go-message/mail"
"github.com/gdamore/tcell/v2"
"github.com/mattn/go-runewidth"
- "github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"git.sr.ht/~rjarry/aerc/completer"
@@ -28,6 +27,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/state"
"git.sr.ht/~rjarry/aerc/lib/templates"
"git.sr.ht/~rjarry/aerc/lib/ui"
+ "git.sr.ht/~rjarry/aerc/lib/xdg"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -650,10 +650,7 @@ func (c *Composer) readSignatureFromFile() []byte {
if sigFile == "" {
return nil
}
- sigFile, err := homedir.Expand(sigFile)
- if err != nil {
- return nil
- }
+ sigFile = xdg.ExpandHome(sigFile)
signature, err := os.ReadFile(sigFile)
if err != nil {
c.aerc.PushError(