From 067ffa8f1a8106496e6f7566fdf2912729a6698b Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Mon, 3 Jul 2023 14:14:56 +0300 Subject: [PATCH] add support for LF_CONFIG/DATA_HOME on unix cc #1209 #1253 --- doc.go | 20 ++++++++++++++------ docstring.go | 22 +++++++++++++++------- lf.1 | 24 ++++++++++++++++++------ os.go | 10 ++++++++-- 4 files changed, 55 insertions(+), 21 deletions(-) diff --git a/doc.go b/doc.go index 782f167f..8b84bb75 100644 --- a/doc.go +++ b/doc.go @@ -288,16 +288,24 @@ History file should be located at: Unix ~/.local/share/lf/history Windows C:\Users\\AppData\Local\lf\history -You can configure the default values of following variables to change these locations: +You can configure these locations with the following variables given with their order of precedences and their default values: Unix - $XDG_CONFIG_HOME ~/.config - $XDG_DATA_HOME ~/.local/share + $LF_CONFIG_HOME + $XDG_CONFIG_HOME + ~/.config + + $LF_DATA_HOME + $XDG_DATA_HOME + ~/.local/share Windows - %ProgramData% C:\ProgramData - %LOCALAPPDATA% C:\Users\\AppData\Local - %LF_CONFIG_HOME% If set, use this value instead of %LOCALAPPDATA% + %ProgramData% + C:\ProgramData + + %LF_CONFIG_HOME% + %LOCALAPPDATA% + C:\Users\\AppData\Local A sample configuration file can be found at https://github.com/gokcehan/lf/blob/master/etc/lfrc.example diff --git a/docstring.go b/docstring.go index 24f6275d..6fb2393f 100644 --- a/docstring.go +++ b/docstring.go @@ -293,17 +293,25 @@ History file should be located at: Unix ~/.local/share/lf/history Windows C:\Users\\AppData\Local\lf\history -You can configure the default values of following variables to change these -locations: +You can configure these locations with the following variables given with their +order of precedences and their default values: Unix - $XDG_CONFIG_HOME ~/.config - $XDG_DATA_HOME ~/.local/share + $LF_CONFIG_HOME + $XDG_CONFIG_HOME + ~/.config + + $LF_DATA_HOME + $XDG_DATA_HOME + ~/.local/share Windows - %ProgramData% C:\ProgramData - %LOCALAPPDATA% C:\Users\\AppData\Local - %LF_CONFIG_HOME% If set, use this value instead of %LOCALAPPDATA% + %ProgramData% + C:\ProgramData + + %LF_CONFIG_HOME% + %LOCALAPPDATA% + C:\Users\\AppData\Local A sample configuration file can be found at https://github.com/gokcehan/lf/blob/master/etc/lfrc.example diff --git a/lf.1 b/lf.1 index 2804db4b..d821aac3 100644 --- a/lf.1 +++ b/lf.1 @@ -334,19 +334,31 @@ History file should be located at: Windows C:\eUsers\e\eAppData\eLocal\elf\ehistory .EE .PP -You can configure the default values of following variables to change these locations: +You can configure these locations with the following variables given with their order of precedences and their default values: .PP .EX Unix - $XDG_CONFIG_HOME ~/.config - $XDG_DATA_HOME ~/.local/share + $LF_CONFIG_HOME + $XDG_CONFIG_HOME + ~/.config +.EE +.PP +.EX + $LF_DATA_HOME + $XDG_DATA_HOME + ~/.local/share .EE .PP .EX Windows - %ProgramData% C:\eProgramData - %LOCALAPPDATA% C:\eUsers\e\eAppData\eLocal - %LF_CONFIG_HOME% If set, use this value instead of %LOCALAPPDATA% + %ProgramData% + C:\eProgramData +.EE +.PP +.EX + %LF_CONFIG_HOME% + %LOCALAPPDATA% + C:\eUsers\e\eAppData\eLocal .EE .PP A sample configuration file can be found at https://github.com/gokcehan/lf/blob/master/etc/lfrc.example diff --git a/os.go b/os.go index 46ee6940..8fbd3338 100644 --- a/os.go +++ b/os.go @@ -84,7 +84,10 @@ func init() { } gUser = u - config := os.Getenv("XDG_CONFIG_HOME") + config := os.Getenv("LF_CONFIG_HOME") + if config == "" { + config = os.Getenv("XDG_CONFIG_HOME") + } if config == "" { config = filepath.Join(gUser.HomeDir, ".config") } @@ -104,7 +107,10 @@ func init() { filepath.Join(config, "lf", "icons"), } - data := os.Getenv("XDG_DATA_HOME") + data := os.Getenv("LF_DATA_HOME") + if data == "" { + data = os.Getenv("XDG_DATA_HOME") + } if data == "" { data = filepath.Join(gUser.HomeDir, ".local", "share") }