fix(history): respect zdotdir config (#83)
closes #82 Also added a `HISTFILE` so it always reads the correct file that the shell is pointing to Is there a `HISTFILE`? If so, use it If it's Zsh: Is there a `ZDOTDIR`? Use `ZDOTDIR/.zsh_history` If it's Fish: Is there an `XDG_DATA_HOME`? Use `XDG_DATA_HOME/fish/fish_history` If none of them are present, revert to the default `$HOME/...`
This commit is contained in:
+11
-7
@@ -66,13 +66,17 @@ func SearchHistory(query string, aliases map[string]string) ([]HistResult, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
var histFile string
|
var histFile string
|
||||||
switch shellName {
|
if envHist := os.Getenv("HISTFILE"); envHist != "" {
|
||||||
case "zsh":
|
histFile = envHist
|
||||||
histFile = filepath.Join(home, ".zsh_history")
|
} else {
|
||||||
case "fish":
|
switch shellName {
|
||||||
histFile = filepath.Join(home, ".local", "share", "fish", "fish_history")
|
case "zsh":
|
||||||
default:
|
histFile = filepath.Join(shell.GetZshConfigDir(), ".zsh_history")
|
||||||
histFile = filepath.Join(home, ".bash_history")
|
case "fish":
|
||||||
|
histFile = filepath.Join(shell.GetFishDataDir(), "fish_history")
|
||||||
|
default:
|
||||||
|
histFile = filepath.Join(home, ".bash_history")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if info, err := os.Stat(histFile); err == nil {
|
if info, err := os.Stat(histFile); err == nil {
|
||||||
|
|||||||
@@ -125,6 +125,14 @@ func GetFishConfigDir() string {
|
|||||||
return filepath.Join(home, ".config", "fish")
|
return filepath.Join(home, ".config", "fish")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetFishDataDir() string {
|
||||||
|
if xdg := os.Getenv("XDG_DATA_HOME"); xdg != "" {
|
||||||
|
return filepath.Join(xdg, "fish")
|
||||||
|
}
|
||||||
|
home, _ := os.UserHomeDir()
|
||||||
|
return filepath.Join(home, ".local", "share", "fish")
|
||||||
|
}
|
||||||
|
|
||||||
func ScanPosixAliases(files []string) map[string]string {
|
func ScanPosixAliases(files []string) map[string]string {
|
||||||
aliases := make(map[string]string)
|
aliases := make(map[string]string)
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
|
|||||||
Reference in New Issue
Block a user