File tree 1 file changed +15
-3
lines changed
1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 9
9
"io"
10
10
"log"
11
11
"os"
12
+ "os/user"
12
13
"path/filepath"
13
14
"runtime"
14
15
"strings"
@@ -427,10 +428,21 @@ func (s *Shell) SetHistoryPath(path string) {
427
428
// SetHomeHistoryPath is a convenience method that sets the history path
428
429
// in user's home directory.
429
430
func (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
+ }
433
444
}
445
+
434
446
abspath := filepath .Join (home , path )
435
447
s .SetHistoryPath (abspath )
436
448
}
You can’t perform that action at this time.
0 commit comments