Making the config directory be XDG base compliant. Closes ~petersanchez/tago#14
1 files changed, 12 insertions(+), 2 deletions(-)

M cmd/tago/main.go
M cmd/tago/main.go +12 -2
@@ 2,6 2,7 @@ package main
 
 import (
 	"os"
+	"path"
 
 	"github.com/spf13/cobra"
 	"hg.code.netlandish.com/~petersanchez/tago"

          
@@ 26,9 27,18 @@ var rootCmd = &cobra.Command{
 }
 
 func init() {
+	root := os.Getenv("XDG_CONFIG_HOME")
+	if root == "" {
+		root = os.Getenv("HOME")
+		if root == "" {
+			root = "~/.config"
+		} else {
+			root = path.Join(root, ".config")
+		}
+	}
+	root = path.Join(root, "tago/tago.db")
 	rootCmd.PersistentFlags().StringVarP(
-		&dbFile, "database", "d", "~/.config/tago/tago.db",
-		"Path to SQLite3 database file.",
+		&dbFile, "database", "d", root, "Path to SQLite3 database file.",
 	)
 	rootCmd.PersistentFlags().BoolVarP(
 		&fullPath, "fullpath", "f", false,