Replace "USERNAME" literals with a constant

This commit is contained in:
Kurtis Rader 2020-08-14 22:20:35 -07:00 committed by Qi Xiao
parent a4e539c823
commit 30d1161ded
2 changed files with 6 additions and 3 deletions

View File

@ -4,12 +4,14 @@ import (
"fmt"
"os"
"path/filepath"
"github.com/elves/elvish/pkg/util"
)
// getSecureRunDir stats elvish-$USERNAME under the default temp dir, creating
// it if it doesn't yet exist, and return the directory name.
func getSecureRunDir() (string, error) {
username := os.Getenv("USERNAME")
username := os.Getenv(util.EnvUSERNAME)
runDir := filepath.Join(os.TempDir(), "elvish-"+username)
err := os.MkdirAll(runDir, 0700)

View File

@ -6,12 +6,13 @@ package util
// Note that some of these env vars may be significant only in special
// circumstances; such as when running unit tests.
const (
EnvELVISH_TEST_TIME_SCALE = "ELVISH_TEST_TIME_SCALE"
EnvHOME = "HOME"
EnvLS_COLORS = "LS_COLORS"
EnvPATH = "PATH"
EnvPATHEXT = "PATHEXT"
EnvPWD = "PWD"
EnvSHLVL = "SHLVL"
EnvLS_COLORS = "LS_COLORS"
EnvUSERNAME = "USERNAME"
EnvXDG_RUNTIME_DIR = "XDG_RUNTIME_DIR"
EnvELVISH_TEST_TIME_SCALE = "ELVISH_TEST_TIME_SCALE"
)