Support customizing HISHTORY_PATH for people who want to install hishtory in an alternate location to fix #54

This commit is contained in:
David Dworken
2022-12-16 22:22:57 -08:00
parent 53e97253e5
commit f8b51e49da
8 changed files with 80 additions and 52 deletions

View File

@ -11,6 +11,7 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"time"
"github.com/ddworken/hishtory/shared"
@ -21,10 +22,13 @@ const (
KdfUserID = "user_id"
KdfEncryptionKey = "encryption_key"
CONFIG_PATH = ".hishtory.config"
HISHTORY_PATH = ".hishtory"
DB_PATH = ".hishtory.db"
)
const (
defaultHishtoryPath = ".hishtory"
)
type HistoryEntry struct {
LocalUsername string `json:"local_username" gorm:"uniqueIndex:compositeindex"`
Hostname string `json:"hostname" gorm:"uniqueIndex:compositeindex"`
@ -163,3 +167,11 @@ func EntryEquals(entry1, entry2 HistoryEntry) bool {
entry1.StartTime.Format(time.RFC3339) == entry2.StartTime.Format(time.RFC3339) &&
entry1.EndTime.Format(time.RFC3339) == entry2.EndTime.Format(time.RFC3339)
}
func GetHishtoryPath() string {
hishtoryPath := os.Getenv("HISHTORY_PATH")
if hishtoryPath != "" {
return hishtoryPath
}
return defaultHishtoryPath
}