File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 99 "io"
1010 "log"
1111 "os"
12+ "os/user"
1213 "path/filepath"
1314 "runtime"
1415 "strings"
@@ -427,10 +428,21 @@ func (s *Shell) SetHistoryPath(path string) {
427428// SetHomeHistoryPath is a convenience method that sets the history path
428429// in user's home directory.
429430func (s * Shell ) SetHomeHistoryPath (path string ) {
430- home := os .Getenv ("HOME" )
431- if runtime .GOOS == "windows" {
432- home = os .Getenv ("USERPROFILE" )
431+ var home string
432+
433+ // Try to get the home directory with user.Current.
434+ // If error occurs, use environment variables
435+ user , err := user .Current ()
436+ if err == nil {
437+ home = user .HomeDir
438+ } else {
439+ if runtime .GOOS == "windows" {
440+ home = os .Getenv ("USERPROFILE" )
441+ } else {
442+ home = os .Getenv ("HOME" )
443+ }
433444 }
445+
434446 abspath := filepath .Join (home , path )
435447 s .SetHistoryPath (abspath )
436448}
You can’t perform that action at this time.
0 commit comments